Rename Excel worksheet using xlsxwriter
Asked Answered
T

3

9

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

Tunis answered 2/1, 2017 at 5:11 Comment(0)
F
19

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.

Fullerton answered 2/1, 2017 at 5:14 Comment(1)
Thanks !! Perfect. I did search in doc. but could not find this example in the worksheet class.Tunis
B
-1

Here, Simple Solution,

        book = xlsxwriter.Workbook('hello.xlsx')
        sheet1 = book.add_worksheet("Match")
        sheet2 = book.add_worksheet("Not_Match")
Bandeau answered 23/5, 2023 at 10:48 Comment(0)
T
-4

Another way without using any modules:

 with open('example.xls', 'r') as f1, open('renamed.xls', 'w') as f2:
     f2.write(f1.read())
Takashi answered 2/1, 2017 at 7:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.