XLSXWriter如何设置开头
目前,我正在使用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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用XLSXWriter,您可以使用工作表
在某些版本的Excel版本中,激活的工作表可能不在屏幕上(尽管将使用最新版本),并且您还必须使用 set_first_page()。
类似的内容:
输出:
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:
Output:
我看到的唯一实例是
openpyxl
您可以设置活动表:
使用
XLSXWRITER
您可以将所需表格设置为第一张纸:The only instance of this I've seen is with
openpyxl
You can set the active sheet:
With
xlsxwriter
you could set the desired sheet to the first sheet: