Ich habe meinen Code noch mal überarbeitet. Ich hoffe er ist jetzt lesbarer.
http://codeviewer.org/view/code:538f
Es kommt zu diesem Fehler:
Code: Alles auswählen
'ascii' codec can't decode byte 0xf6 in position 26: ordinal not in range(128)
Traceback (most recent call last):
File "Doku_nach_Excel.py", line 129, in CreateXlsxFile
workbook.close()
File "C:\python27\lib\xlsxwriter\workbook.py", line 295, in close
self._store_workbook()
File "C:\python27\lib\xlsxwriter\workbook.py", line 518, in _store_workbook
xml_files = packager._create_package()
File "C:\python27\lib\xlsxwriter\packager.py", line 140, in _create_package
self._write_shared_strings_file()
File "C:\python27\lib\xlsxwriter\packager.py", line 280, in _write_shared_strings_file
sst._assemble_xml_file()
File "C:\python27\lib\xlsxwriter\sharedstrings.py", line 53, in _assemble_xml_file
self._write_sst_strings()
File "C:\python27\lib\xlsxwriter\sharedstrings.py", line 83, in _write_sst_strings
self._write_si(string)
File "C:\python27\lib\xlsxwriter\sharedstrings.py", line 110, in _write_si
self._xml_si_element(string, attributes)
File "C:\python27\lib\xlsxwriter\xmlwriter.py", line 122, in _xml_si_element
self.fh.write("""<si><t%s>%s</t></si>""" % (attr, string))
File "C:\python27\lib\codecs.py", line 694, in write
return self.writer.write(data)
File "C:\python27\lib\codecs.py", line 357, in write
data, consumed = self.encode(object, self.errors)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf6 in position 26: ordinal not in range(128)
Wenn ich die diese Funktion einsetze:
Code: Alles auswählen
def CreateXlsxFile(IniFile, DirectoryList):
GlobalLogger.info('start function "CreateXlsxFile"')
DestinationDirectory = ReadIniValue(IniFile, "Verzeichnisse",
"Ausgabe_Verzeichnis")
NameXlsxFile = ReadIniValue(IniFile, "Verzeichnisse",
"Name_Excel_Datei")
try:
XlsxFilePath = os.path.join(DestinationDirectory, NameXlsxFile)
workbook = xlsxwriter.Workbook(XlsxFilePath)
worksheet = workbook.add_worksheet('FindeInDocu')
for zeile, Directory in enumerate(DirectoryList, 1):
for spalte, path in enumerate(PathToList(Directory)[2:]):
GlobalLogger.debug('Directory= ' + Directory)
url = r'external:%s' %Directory
url.decode('iso-8859-1')
print (type(url))
worksheet.write_url(row=zeile, col=spalte, url=url , string=path)
workbook.close()
GlobalLogger.info('function "CreateXlsxFile" finished without Error')
except Exception, e:
GlobalLogger.error('function "CreateXlsxFile" finished with Error')
GlobalLogger.exception(e, exc_info=True)
Kommt es zu diesem Fehler:
Code: Alles auswählen
'ascii' codec can't decode byte 0xf6 in position 26: ordinal not in range(128)
Traceback (most recent call last):
File "Doku_nach_Excel.py", line 129, in CreateXlsxFile
workbook.close()
File "C:\python27\lib\xlsxwriter\workbook.py", line 295, in close
self._store_workbook()
File "C:\python27\lib\xlsxwriter\workbook.py", line 518, in _store_workbook
xml_files = packager._create_package()
File "C:\python27\lib\xlsxwriter\packager.py", line 140, in _create_package
self._write_shared_strings_file()
File "C:\python27\lib\xlsxwriter\packager.py", line 280, in _write_shared_strings_file
sst._assemble_xml_file()
File "C:\python27\lib\xlsxwriter\sharedstrings.py", line 53, in _assemble_xml_file
self._write_sst_strings()
File "C:\python27\lib\xlsxwriter\sharedstrings.py", line 83, in _write_sst_strings
self._write_si(string)
File "C:\python27\lib\xlsxwriter\sharedstrings.py", line 110, in _write_si
self._xml_si_element(string, attributes)
File "C:\python27\lib\xlsxwriter\xmlwriter.py", line 122, in _xml_si_element
self.fh.write("""<si><t%s>%s</t></si>""" % (attr, string))
File "C:\python27\lib\codecs.py", line 694, in write
return self.writer.write(data)
File "C:\python27\lib\codecs.py", line 357, in write
data, consumed = self.encode(object, self.errors)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xf6 in position 26: ordinal not in range(128)
Meine Vermutung ist nun das XlsxWrter nur ascii umgehen kann. Oder nach ascii konvertieren will dies geht aber nicht...
Ich habe keinen Schimmer. :K