我有一个列表,例如:
[
[u'email', u'salutation', u'firstname', u'lastname', u'remarks', None, None, None, None, None],
[u'[email protected]', u'Mr', u'Daniel', u'Radcliffe', u'expecto patronum', None, None, None, None, None],
[u'[email protected]', u'Mr', u'Severus', u'Snape', u'Always', None, None, None, None, None],
]
我想将其插入到 Excel 文件中。可以通过编写每个元素来逐一执行此操作。
book = xlwt.Workbook(encoding="utf-8")
sheet1 = book.add_sheet("Sheet 1")
row = 0
for l in listdata:
col = 0
for e in l:
if e:
sheet1.write(row, col, e)
col+=1
row+=1
但这种方法看起来效率不高,因为必须遍历整个列表的每个元素。有没有更有效的方法在 python 中执行相同的操作xlwt
?