Adding more than 10 worksheets with the same name results in a broken Excel file.

Issue #470 resolved
Joakim Israelsson created an issue

_unique_sheet_name will enumerate worksheets with identical names all the way up to sheet9 and then keep adding sheet10 after that.

This results in a file that Excel considers broken and that must be repaired. I think it would be a better behavior to throw a SheetTitleException to make the application aware of the problem and then let the caller come up with better names.

Comments (6)

  1. CharlieC

    Thanks for the report. Raising an exception is probably not the right thing to do: why for more than 10 worksheets? Might as well just do it with the first duplicate and leave naming entirely to client code. Or just keep on counting.

  2. Joakim Israelsson reporter

    Actually my original reason was that for us, adding another digit would make the title too long. I guess it would make more sense to keep counting and raise the "Maximum 31 characters allowed in sheet title" exception when the title becomes too long.

    It's still possible for the client code to implement the naming themselves (like we do now) but with that solution we would just truncate the name string at 25 characters instead of 30 and be done with it.

  3. CharlieC

    The automatic renaming is mainly for simple use so that you can just use wb.add_sheet() and live with the defaults. It's a little more intelligent to handle Excel's obsession with localising everything so that it works as well with "Blatt1" and "Feuille1" as it does with "Sheet1". It's pretty dumb code and can probably be tweaked to keep counting.

  4. Joakim Israelsson reporter

    That simple use works really well for now actually, except for this particular bug. Right now it only captures one digit so whatever-name-here10 becomes the digit 1. Changing the regex to catch all digits at the end might be enough.

  5. Log in to comment