Rename Excel worksheet using xlsxwriter

懵懂的女人 提交于 2019-12-11 00:58:43

问题


How do i rename excel worksheet using xlsxwriter in python. I am using python 2.7 in linux to create excel reports. But cannot find an option to rename the tabs


回答1:


You can set the name of a worksheet while adding it via add_worksheet():

worksheet = workbook.add_worksheet('My Custom Name')

Note that you cannot set the name of an existing worksheet:

There is no set_name() method. The only safe way to set the worksheet name is via the add_worksheet() method.




回答2:


Another way without using any modules:

 with open('example.xls', 'r') as f1, open('renamed.xls', 'w') as f2:
     f2.write(f1.read())


来源:https://stackoverflow.com/questions/41421631/rename-excel-worksheet-using-xlsxwriter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!