gpt4 book ai didi

Python Xlsxwriter 无法正常工作

转载 作者:行者123 更新时间:2023-12-02 01:03:17 26 4
gpt4 key购买 nike

我是 Python 新手,我正在尝试使用这个简单的代码,一切正常,但序列不会重复。请帮助我。

this is the excel output

import xlsxwriter

workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet()

expenses = (
['Rent', 1000],
['Gas', 100],
['Food', 300],
['Gym', 50],
)

row = 0
col = 0

for item, cost in (expenses):
worksheet.write(row, col, item)
worksheet.write(row, col + 1, cost)
row += 1


workbook.close()

最佳答案

您需要在 workbook.close() 之前删除缩进:

import xlsxwriter

workbook = xlsxwriter.Workbook('test.xlsx')
worksheet = workbook.add_worksheet()

expenses = (
['Rent', 1000],
['Gas', 100],
['Food', 300],
['Gym', 50],
)

row = 0
col = 0

for item, cost in (expenses):
worksheet.write(row, col, item)
worksheet.write(row, col + 1, cost)
row += 1


workbook.close()

关于Python Xlsxwriter 无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50447854/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com