Have a scenario where I wanted to change the name of the "Sheet" in the spread-sheet.
a. I tried created a spread-sheet saying ss = Workbook()
. Think, this is creating the spread-sheet with a sheet named "Sheet"
b. I tried changing the name of the sheet using the below format,
ss_sheet = ss.get_sheet_by_name('Sheet') ss_sheet.Name = 'Fruit'
But then the above step is not changing the sheet name as required. Is there anything wrong in the above step ? Kindly comment on the same.
Thanks
Click the tab of the sheet you want to rename. Select Rename... from the menu that appears. Type the desired name for the sheet. Click anywhere outside of the tab or press Enter on your keyboard when you're finished, and the sheet will be renamed.
Use the os. rename() method to rename a file in a folder. Pass both the old name and a new name to the os. rename(old_name, new_name) function to rename a file.
Normally, we can easily rename a worksheet with right clicking the sheet in the Sheet Tab and selecting Rename from right-clicking menu in Excel.
You can do this by doing the following:
import openpyxl ss=openpyxl.load_workbook("file.xlsx") #printing the sheet names ss_sheet = ss['Sheet'] ss_sheet.title = 'Fruit' ss.save("file.xlsx")
This works for me. Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With