xlsxwriter没有创建所需的Excell文件(xlsxwriter not creating a desired Excell file)

编程入门 行业动态 更新时间:2024-10-27 04:27:43
xlsxwriter没有创建所需的Excell文件(xlsxwriter not creating a desired Excell file)

我已经为xlsxwriter网站提供了这个基本代码。 据他们说,这段代码应该打开一个带有hello写在A1方块中的Excel文件,但似乎没有创建任何东西,并且在扫描我的计算机找到该文件后,我的怀疑得到了证实。

import xlsxwriter workbook = xlsxwriter.Workbook("hello.xlsx") worksheet = workbook.add_worksheet() worksheet.write('A1', 'Hello world') workbook.close()

I have taken this basic code for the xlsxwriter website. According to them, this code should open a Excel file with hello written in the A1 square, but nothing seems to have been created and after having scanned my computer for the file my suspicion was confirmed.

import xlsxwriter workbook = xlsxwriter.Workbook("hello.xlsx") worksheet = workbook.add_worksheet() worksheet.write('A1', 'Hello world') workbook.close()

最满意答案

这段代码确实有效:

import xlsxwriter workbook = xlsxwriter.Workbook(r'C:\hello.xlsx') worksheet = workbook.add_worksheet() worksheet.write('A1', 'Hello world') workbook.close()

您应该指定要创建的文件的位置。 例如r'C:\hello.xlsx'而不仅仅是文件的名称。 此外,您需要关闭工作簿,而不是工作表。

仅供参考:要格式化代码,只需将代码缩进四个空格即可。

This code does work:

import xlsxwriter workbook = xlsxwriter.Workbook(r'C:\hello.xlsx') worksheet = workbook.add_worksheet() worksheet.write('A1', 'Hello world') workbook.close()

You should specify where the file to be created will go. For example r'C:\hello.xlsx' rather than just the name of the file. Also, you need to close the workbook, not the worksheet.

FYI: To format your code, just indent code by four spaces.

更多推荐

本文发布于:2023-07-26 08:10:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1272895.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:所需   文件   Excell   xlsxwriter   desired

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!