XLSXWriter如何设置开头

发布于 2025-01-24 22:36:11 字数 788 浏览 2 评论 0原文

目前,我正在使用XLSXWRITER在Python中生成光泽。我创建了一个带有52张纸的Excel文档(一年中每周为1张)。生成整个文档的运行良好,但是打开文档时,它总是在第一张纸(第1周)上打开。我正在尝试将开场白设置为当前一周。目前,我正在生成文档,如下所示:

weeks = 52   # amount of weeks in a year
Excel_sheets = []  # empty list for creating new sheets
path = r"C:/Users/menno/Documents/calender.xlsx"  # location for the excel file

Excel_doc = xlsxwriter.Workbook(path)  # create file at given path

for week in range(weeks):  # loopt through amount of weeks
    Excel_sheets.append(Excel_doc.add_worksheet("Week " + str(week + 1)))  # for every week make a new sheet

因此,现在我生成了一个带有52张纸的Excel文件,每个文件都命名为“第1周”,直到“第52周”。然后,我将数据放在每个纸上,最后将其关闭。当我打开文档时,它将始终在第一张纸上打开。有什么办法可以做到这一点,因此它会自动在不同的工作表上打开,或者更具体地说,打开文件生成的当前一周?

我浏览了XSLXWriter文档,但找不到允许我设置起始表的功能。如果有人有任何想法,请告诉我。提前致谢!

Currently I'm working on generating a calender in Python using XlsxWriter. I've created an Excel document with 52 sheets (1 for every week in a year). Generating the entire document works perfectly fine but when opening the document, it always opens on the first sheet (week 1). I'm trying to set the opening sheet to the current week. Currently I'm generating my document as follows:

weeks = 52   # amount of weeks in a year
Excel_sheets = []  # empty list for creating new sheets
path = r"C:/Users/menno/Documents/calender.xlsx"  # location for the excel file

Excel_doc = xlsxwriter.Workbook(path)  # create file at given path

for week in range(weeks):  # loopt through amount of weeks
    Excel_sheets.append(Excel_doc.add_worksheet("Week " + str(week + 1)))  # for every week make a new sheet

So now I've generated an Excel file with 52 sheets, each one named "week 1" until "week 52". I then put data in each sheet and finally I close it. When I open the document it will always open on the first sheet. Is there any way I can make it so it automatically opens on a different sheet, or more specifically, open the current week that the file was generated in?

I looked through the XslxWriter documentation but I couldn't find a function that allows me to set a starting sheet. If anyone has any idea then please let me know. Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

深陷 2025-01-31 22:36:11

使用XLSXWriter,您可以使用工作表

在某些版本的Excel版本中,激活的工作表可能不在屏幕上(尽管将使用最新版本),并且您还必须使用 set_first_page()

类似的内容:

import xlsxwriter

weeks = 52
Excel_sheets = []
path = r"calender.xlsx"

Excel_doc = xlsxwriter.Workbook(path)

for week in range(weeks):
    Excel_sheets.append(Excel_doc.add_worksheet("Week " + str(week + 1)))

Excel_sheets[19].set_first_sheet()
Excel_sheets[20].activate()

Excel_doc.close()

输出

”在此处输入图像描述”

With XlsxWriter you can can set the visible worksheet with the worksheet activate() method.

In some versions of Excel the activated worksheet may not be on the screen (although with most recent versions it will be) and you may also have to set the first visible worksheet using set_first_page().

Something like this:

import xlsxwriter

weeks = 52
Excel_sheets = []
path = r"calender.xlsx"

Excel_doc = xlsxwriter.Workbook(path)

for week in range(weeks):
    Excel_sheets.append(Excel_doc.add_worksheet("Week " + str(week + 1)))

Excel_sheets[19].set_first_sheet()
Excel_sheets[20].activate()

Excel_doc.close()

Output:

enter image description here

╰つ倒转 2025-01-31 22:36:11

我看到的唯一实例是openpyxl
您可以设置活动表:

wb.active = sheetnum

使用XLSXWRITER您可以将所需表格设置为第一张纸:

sheetname.set_first_sheet()

The only instance of this I've seen is with openpyxl
You can set the active sheet:

wb.active = sheetnum

With xlsxwriter you could set the desired sheet to the first sheet:

sheetname.set_first_sheet()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文