How to rename the sheet name in the spread-sheet using Python?
<p>Have a scenario where I wanted to change the name of the "Sheet" in the spread-sheet.</p>

<p>a. I tried created a spread-sheet saying <code>ss = Workbook()</code>. Think, this is creating the spread-sheet with a sheet named "Sheet"</p>

<p>b. I tried changing the name of the sheet using the below format, </p>

<pre><code>ss_sheet = ss.get_sheet_by_name('Sheet')
ss_sheet.Name = 'Fruit'
</code></pre>

<p>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.</p>

<p>Thanks</p>

<p>You can do this by doing the following:</p>

<pre><code>import openpyxl
ss=openpyxl.load_workbook("file.xlsx")
#printing the sheet names
ss_sheet = ss.get_sheet_by_name('Sheet')
ss_sheet.title = 'Fruit'
ss.save("file.xlsx")
</code></pre>

<p>This works for me. Hope this helps.</p>

python python-2.7