Worksheet set title unexpected behaviour when title starts with "Sheet" string
Created originally on Bitbucket by Hunter_71 (Tomasz Zięba)
Sometimes openpyxl worksheet tilte is different with given string after simple set:
#!python
my_worksheet_title = "Sheet2"
(...)
worksheet = wb.create_sheet()
worksheet.title = my_worksheet_title
Problem occurs for titles starting with "Sheet" prefix. I wrote python script with assersions which presents some cases when problem occured. I attach my file to this issue.
Example:
#!bash
AssertionError: List of exsisting worksheet titles:
['Sheet', 'Foo', 'Baz', 'Sheet2', 'Sheet31', 'Bar', 'Sheet41', 'Sheet6']
expected:
['Sheet', 'Foo', 'Baz', 'Sheet2', 'Sheet3', 'Bar', 'Sheet4', 'Sheet6']
Piece of code for above example:
#!python
titles = ["Foo", "Baz", "Sheet2", "Sheet3", "Bar", "Sheet4", "Sheet6"]
workbook = openpyxl.Workbook()
for title in titles:
worksheet = workbook.create_sheet()
worksheet.title = title
titles.insert(0, 'Sheet')
assert workbook.get_sheet_names() == titles, \
"List of exsisting worksheet titles:\n{}\nexpected:\n{}".format(
workbook.get_sheet_names(), titles
)
Attachments: openpyxl_wokrsheet_title_unexpected_behaviour.py