Ich habe eine Liste von Listen in Python. Ich möchte schreiben einzelne Liste als Zeile in xlwt.Python - Schreiben Listenwerte in xlwt
datalist = [['India', 'Yes', '99%'], [['China', 'Yes', '89%'], ['Brazil', 'No', '90%']], ['Russia', 'Yes', '92%'], [['Germany', 'No', '97%'], ['Spain', 'No', '70%']]]
Zuerst habe ich die Gesamtzahl der Liste def zählen (local_list) berechnet:
def listcount(lst):
listsum = 0
for item in lst:
if not isinstance(l,list):
return 1
else:
listsum+= listcount(item)
return listsum
excel_export.py
import xlwt
book = xlwt.Workbook()
sheet = book.add_sheet("PySheet1")
for rownum in range(listcount(datalist)):
row = sheet.row(rownum)
for index, col in enumerate(datalist):
# do something similar like in listcount()
# check if instance is list if not then write the value
# rownum will act as a row
# column value will come from list item
row.write(row, col, val)
book.save("test.xls")
Sample
Wie kann ich Listenwerte in entsprechende Zeilen und Spalten schreiben?
Beispiel hinzufügen Excel-Ausgabetabelle. –
@ VedangMehta- Excel-Probe hinzugefügt! – MysticCodes