Bug 49887 - Inconsistent behaviour between HSSF and XSSF when creating a sheet with a too long name
Summary: Inconsistent behaviour between HSSF and XSSF when creating a sheet with a too...
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: 3.7-dev
Hardware: PC All
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-06 14:51 UTC by Martin Studer
Modified: 2010-09-07 03:11 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Studer 2010-09-06 14:51:40 UTC
workbook.createSheet(name) with a name of > 30 characters throws an exception for XSSF workbooks (e.g. "sheetName 'A very very very very very very very very long name' is invalid - must be 1-30 characters long") while for HSSF workbooks createSheet just seems to truncate sheet names to 31 characters.

I would expect both XSSF and HSSF to throw an exception stating the correct number of maximum allowed characters (31 ???).


POI: 3.7-build2
OS: Windows 7 64-bit
Java: 1.6.0_20 64-bit
Comment 1 Yegor Kozlov 2010-09-07 03:11:33 UTC
The rule is more complex. 

Non Excel clients such as OpenOffice allow opening / editing of worksheets with names longer than 31 characters. 
Excel (2007) opens files with long sheet names without error or warning. However, long sheet names are silently truncated to 31 chars.  This means that sheet name uniqueness is enforced on only the first 31 chars.

Example:

 workbook.createSheet("POI allows creating sheets with names longer than 31 characters - 1"); // OK
 workbook.createSheet("POI allows creating sheets with names longer than 31 characters - 2"); // fail, substring(0, 31) is the same as sheet0

I changed XSSF to behave as HSSF, i.e. removed the 31 chars restriction and enforced name uniqueness on the first 31 chars. 

The fix was committed in r993246

Regards,
Yegor