openpyxl如何在工作表中写入列表数据? [英] How can openpyxl write list data in sheet?
问题描述
最近我正在使用openpyxl处理一些科学数据,当我将列表数据写入excel文件时,我遇到了问题.
recently I am using openpyxl to deal with some scientific data, when I was writting the list data to a excel file, I have a problem.
datalist[row][col]
wb=openpyxl.Workbook(optimized_write=Ture)
ws_write = wb.create_sheet(0)
for i in range(row):
ws_write.append([datalist[i][0]])
wb.save(filename='data.xlsx')
完成后,似乎只能将列表写入xlsx文件的第一个col中,如何将我的数据列表的相同col分配给同一工作表中的xlsx文件的col?有控制输出的参考吗?
when it is done, seems like that it only can write the list into the first col of the xlsx file, how can I assign the same col of my datalist to the same col of xlsx file in the same sheet? Is there any reference to control the output?
非常感谢
推荐答案
使用ws.append(row)
时,您必须以序列或生成器的形式整体插入pass.我不了解您的数据结构,但是类似以下的内容应该可以工作.
When using ws.append(row)
you must insert pass in a whole either as sequence or as a generator. I don't understand your data structure but something like the following should work.
for row in datalist:
ws.append(row)
如果这还不够,请提供有关数据结构的更多信息.
If this is not sufficient then please provide more information about the structure of your data.
这篇关于openpyxl如何在工作表中写入列表数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!