Skip to content

openxlsx allows invalid characters in worksheet names #211

@jonas-hag

Description

@jonas-hag

Describe the bug
openxlsx allows writing worksheet names that are not supported by Excel.

To Reproduce

  1. Save an example file:
library(openxlsx)
write.xlsx(
  mtcars,
  file = "~/test.xlsx",
  sheetName = "mtcars/test"
)
  1. Open the file
  2. The error message says:

We found a problem with some content in ’test.xlsx’. Do you want us to try to recover as much as we can? If you trust the source of this workbook, click Yes.

  1. When you try to manually include a / in a worksheet name within Excel, you get the message:

You've typed an invalid name for a sheet or chart. Make sure that:
• The name that you type does not exceed 31 characters.
• The name does not contain any of the following characters: : \ / ? * [ or ].
• You did not leave the name blank.

Expected behavior
write.xlsx should throw an error when any of the above characters are included in a worksheet name.

Desktop (please complete the following information):

  • OS: macOS
  • openxlsx 4.2.3

Additional context
I'm happy to provide a PR if it should be done in the R code, possibly in buildWorkbook?

Metadata

Metadata

Assignees

No one assigned

    Labels

    StalefixedFixed, issue will be closed within 7 dayswaiting for answerIf not answered, the issue will be closed in 7 days.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions