[英]How to export data to xlsx using xlsxwriter for python
I am having trouble writing data to excel files. 我无法将数据写入excel文件。 Running this code does not write the file to the expected folder. 运行此代码不会将文件写入期望的文件夹。
import xlsxwriter
workbook = xlsxwriter.Workbook('C:\\Users\\hburk\\Desktop\\Python\\sqloutput.xlsx')
east = workbook.add_worksheet()
eastdata = (
['apples', 4.0],
['bananas', 5.0],
)
row = 1
col = 0
for pointname, price in eastdata:
east.write_string(row, col, pointname)
east.write(row, col+1, price)
row += 1
workbook.close()
Edits: I changed the silly errors: eastres and east.close() - I tried to simplify this from the original code and mucked some things up. 编辑:我更改了一些愚蠢的错误:eastres和east.close()-我试图从原始代码中简化此代码,并做了一些修改。 The code still doesn't work as written here. 该代码仍然无法按此处编写的方式工作。
只是不要忘记关闭Workbook
:
workbook.close()
The code still doesn't work as written here. 该代码仍然无法按此处编写的方式工作。
If you fix the indentation it should work. 如果您修复了缩进,它应该可以工作。 I ran this: 我跑了这个:
import xlsxwriter
workbook = xlsxwriter.Workbook('sqloutput.xlsx')
east = workbook.add_worksheet()
eastdata = (
['apples', 4.0],
['bananas', 5.0],
)
row = 1
col = 0
for pointname, price in eastdata:
east.write_string(row, col, pointname)
east.write(row, col+1, price)
row += 1
workbook.close()
And got this: 并得到了:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.