Bug 49907 - Inconsistent behaviour between HSSF and XSSF when creating consecutive names
Summary: Inconsistent behaviour between HSSF and XSSF when creating consecutive names
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-10 05:27 UTC by Martin Studer
Modified: 2010-09-11 08:48 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-10 05:27:01 UTC
Consider the following code:

Workbook wb = new HSSFWorkbook();
wb.createName();
wb.createName();

This fails for HSSF with the following error message:
"You are trying to assign a duplicated name record: "

For XSSFWorkbook's there is no problem.


It's not quite clear to me which behaviour is more appropriate...

POI: 3.7-build2
OS: Windows 7 64-bit
Java: 1.6.0_20 64-bit
Comment 1 Yegor Kozlov 2010-09-11 08:48:30 UTC
Strictly speaking your code snippet does not make sense. Name's name and formula MUST be set, otherwise Excel will complain on unreadable content.  

However, it should be possible to create two consecutive names and initialize them later:

Workbook wb = new HSSFWorkbook(); //or new XSSFWorkook()
Name name1 = wb.createName();
Name name2 = wb.createName();

name1.setNameName("sale_1");
name1.setRefersToFormula(1);

name2.setNameName("sale_2");
name2.setRefersToFormula(2);


The following code works in XSSF but fails in HSSF - checking uniqueness of names in HSSF is too aggressive. Both should allow creating a pool of names and initialize them later. 

I committed the fix in r996136. 

Thanks,
Yegor