Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a type check for the sheetname #1064

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions xlsxwriter/test/workbook/test_check_sheetname.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ def test_check_sheetname(self):
exp = "Sheet4"
self.assertEqual(got, exp)

def test_check_sheetname_with_incorrect_dtype(self):
"""Test the _check_sheetname() method with exception"""

name = 42
self.assertRaises(TypeError, self.workbook._check_sheetname, name)

def test_check_sheetname_with_long_name(self):
"""Test the _check_sheetname() method with exception"""

Expand Down
5 changes: 5 additions & 0 deletions xlsxwriter/workbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,11 @@ def _check_sheetname(self, sheetname, is_chartsheet=False):
else:
sheetname = self.sheet_name + str(self.sheetname_count)

if not isinstance(sheetname, str):
raise TypeError(
"The sheet name must be of type str, is type %s." % type(sheetname)
)

# Check that sheet sheetname is <= 31. Excel limit.
if len(sheetname) > 31:
raise InvalidWorksheetName(
Expand Down
Loading