Save sheet from excel to text user Kantale

From PyPedia
Jump to: navigation, search

Contents

[edit] Documentation

Saves a sheet of an Excel file to a text file. It uses the xlrd http://pypi.python.org/pypi/xlrd library.


[edit] Parameters

<inputs>
</inputs>


[edit] Return

None

[edit] See also

Extract_list_of_sheets_from_excel_to_text_user_Kantale

[edit] Code

try:
        import xlrd
except ImportError as inst:
        print "xlrd has not been installed. Please refer to http://pypi.python.org/pypi/xlrd for downloading and installing. Exiting.."
        raise inst


def Save_sheet_from_excel_to_text_user_Kantale(
                        excelFilename=None,
                        excelBook=None,
                        nameOfSheet=None,
                        indexOfSheet=None,
                        outputFilename=None,
                        functionsToApplyToColumns=None):
        #Open the excel:
        book = xlrd.open_workbook(excelFilename) if excelBook == None else excelBook

        #Open the sheet
        sheet = book.sheet_by_index(indexOfSheet) if nameOfSheet == None else book.sheet_by_name(nameOfSheet)

        #Open output filename
        outputFile = open(outputFilename, "w")

        for row in range(sheet.nrows):
                rowToPrint = []
                for cellIndex, cell in enumerate(sheet.row(row)):
                        if functionsToApplyToColumns != None and functionsToApplyToColumns.has_key(cellIndex):
                                rowToPrint += [str(functionsToApplyToColumns[cellIndex](str(cell.value)))]
                        else:
                                rowToPrint += [str(cell.value)]
                outputFile.write(str.join("\t", rowToPrint) + "\n")

        outputFile.close()

[edit] Unit Tests

def uni1():
   return True

[edit] Development Code

def Save_sheet_from_excel_to_text_user_Kantale():
	pass

[edit] Permissions

[edit] Documentation Permissions

Kantale

[edit] Code Permissions

Kantale

[edit] Unit Tests Permissions

Kantale

[edit] Permissions Permissions

Kantale

Personal tools
Namespaces

Variants
Actions
Navigation
Toolbox