如何将列表的内容复制到excel

时间:2017-08-16 14:26:38

标签: excel python-3.x

设置:我使用的是jupyter笔记本,Python版本3.6.2和Excel版本15.36

任务:我创建了一个列表,并希望将其内容按列逐列复制到空白Excel文件的第一行。

这是我的代码:

for rowOfCellObjects in strauss_sheet(1, list_length):
    for cellObj in rowOfCellObjects:
        for item in noreplist:
            sheet.cellObj(row=1, column=colNum).value = item

我收到错误,因为'Worksheet'对象不可调用。 我的列表长度存储在list_length中,我的列表是noreplist

我是python的新手,很想听听执行此任务的好方法。

1 个答案:

答案 0 :(得分:0)

使用xlwt

可以轻松完成此操作
import xlwt

wb = xlwt.Workbook()
ws = wb.add_sheet('Sheet 1')

listdata = ['write', 'list', 'to', 'excel', 'row']

first_row = 0

# write each item in the list to consecutive columns on the first row
for index, item in enumerate(listdata):
        ws.write(first_row, index, item) 

wb.save('example.xls')

生成包含内容的excel文件:

write list to excel row

希望这有帮助。