Python Konvertieren von Excel nach CSV

Scheint, es gibt eine Menge Beiträge zu diesem Thema und meine Lösung ist im Einklang mit dem, was die häufigste Antwort scheint zu sein, allerdings bin ich auf ein encoding-Fehler, dass ich nicht weiß, wie.

>>> def Excel2CSV(ExcelFile, SheetName, CSVFile):
     import xlrd
     import csv
     workbook = xlrd.open_workbook(ExcelFile)
     worksheet = workbook.sheet_by_name(SheetName)
     csvfile = open(CSVFile, 'wb')
     wr = csv.writer(csvfile, quoting=csv.QUOTE_ALL)

     for rownum in xrange(worksheet.nrows):
         wr.writerow(worksheet.row_values(rownum))

     csvfile.close()

>>> Excel2CSV(r"C:\Temp\Store List.xls", "Open_Locations", 
              r"C:\Temp\StoreList.csv")

Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
Excel2CSV(r"C:\Temp\Store List.xls", "Open_Locations", r"C:\Temp\StoreList.csv")
File "<pyshell#1>", line 10, in Excel2CSV
wr.writerow(worksheet.row_values(rownum))
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 14:
ordinal not in range(128)
>>>

Jede Hilfe oder Einsicht wird sehr geschätzt.

InformationsquelleAutor MrBubbles | 2014-09-25

Schreibe einen Kommentar