fixed inconsistent behaviour between HSSF and XSSF when creating consecutive names, see Bugzilla 49907

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@996136 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yegor Kozlov 2010-09-11 12:45:59 +00:00
parent 216bcfea03
commit 442579c326
4 changed files with 30 additions and 7 deletions

View File

@ -34,6 +34,7 @@
<changes>
<release version="3.7-beta3" date="2010-??-??">
<action dev="poi-developers" type="fix">49907 - fixed inconsistent behaviour between HSSF and XSSF when creating consecutive names</action>
<action dev="poi-developers" type="add">Add getMimeType() method to HWPF Picture, alongside existing file extension</action>
<action dev="poi-developers" type="add">Add code for reading Ole10Native data</action>
<action dev="poi-developers" type="add">Add getMimeType() method to HSSF/XSSF PictureData, alongside existing file extension</action>

View File

@ -1863,11 +1863,6 @@ public final class InternalWorkbook {
{
LinkTable linkTable = getOrCreateLinkTable();
if(linkTable.nameAlreadyExists(name)) {
throw new IllegalArgumentException(
"You are trying to assign a duplicated name record: "
+ name.getNameText());
}
linkTable.addName(name);
return name;
@ -1884,7 +1879,7 @@ public final class InternalWorkbook {
NameRecord name = new NameRecord(builtInName, sheetNumber);
while(linkTable.nameAlreadyExists(name)) {
if(linkTable.nameAlreadyExists(name)) {
throw new RuntimeException("Builtin (" + builtInName
+ ") already exists for sheet (" + sheetNumber + ")");
}

View File

@ -465,7 +465,9 @@ public class XSSFWorkbook extends POIXMLDocument implements Workbook, Iterable<X
}
public XSSFName createName() {
XSSFName name = new XSSFName(CTDefinedName.Factory.newInstance(), this);
CTDefinedName ctName = CTDefinedName.Factory.newInstance();
ctName.setName("");
XSSFName name = new XSSFName(ctName, this);
namedRanges.add(name);
return name;
}

View File

@ -559,4 +559,29 @@ public abstract class BaseTestNamedRange extends TestCase {
n.setFunction(false);
assertFalse(n.isFunctionName());
}
public final void testDefferedSetting() {
Workbook wb = _testDataProvider.createWorkbook();
Name n1 = wb.createName();
assertNull(n1.getRefersToFormula());
assertEquals("", n1.getNameName());
Name n2 = wb.createName();
assertNull(n2.getRefersToFormula());
assertEquals("", n2.getNameName());
n1.setNameName("sale_1");
n1.setRefersToFormula("10");
n2.setNameName("sale_2");
n2.setRefersToFormula("20");
try {
n2.setNameName("sale_1");
fail("Expected exception");
} catch(Exception e){
assertEquals("The workbook already contains this name: sale_1", e.getMessage());
}
}
}