Summary: | Check for existing Sheet fails for names > 31 characters | ||
---|---|---|---|
Product: | POI | Reporter: | Laura Henning <laura-marie.henning> |
Component: | SS Common | Assignee: | POI Developers List <dev> |
Status: | RESOLVED INVALID | ||
Severity: | normal | ||
Priority: | P2 | ||
Version: | 5.0.0-FINAL | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | All | ||
Attachments: | MWE |
the current XSSFWorkbook has this code ``` // YK: Mimic Excel and silently truncate sheet names longer than 31 characters if(sheetname.length() > 31) { sheetname = sheetname.substring(0, 31); } ``` I'll try removing this Actually, I currently only have access to hosted Excel on Sharepoint and it rigidly enforces a 31 char limit on worksheet names - so no, I don't think it is a good idea to remove this in POI. Maybe what we need is to throw an exception if someone tries to use a 32 or more char sheet name. the existing behaviour is clearly documented in the Javadocs. ``` * Note that Excel allows sheet names up to 31 chars in length but other applications * (such as OpenOffice) allow more. Some versions of Excel crash with names longer than 31 chars, * others - truncate such names to 31 character. * <p> * POI's SpreadsheetAPI silently truncates the input argument to 31 characters. * Example: * * <pre>{@code * Sheet sheet = workbook.createSheet("My very long sheet name which is longer than 31 chars"); // will be truncated * assert 31 == sheet.getSheetName().length(); * assert "My very long sheet name which i" == sheet.getSheetName(); * }</pre> ``` Also this: ``` * See {@link WorkbookUtil#createSafeSheetName(String nameProposal)} * for a safe way to create valid names ``` Closing as invalid |
Created attachment 38033 [details] MWE When creating a Sheet with a name that exceeds 31 characters, the check if that Sheet already exists in the Workbook fails and an IllegalArgumenException (The workbook already contains a sheet named ...) is thrown. When chopping the name to <=31 characters the exact same code works. See the attached MWE for an example.