]> source.dussan.org Git - poi.git/commitdiff
fixed inconsistent behaviour between HSSF and XSSF when creating consecutive names...
authorYegor Kozlov <yegor@apache.org>
Sat, 11 Sep 2010 12:45:59 +0000 (12:45 +0000)
committerYegor Kozlov <yegor@apache.org>
Sat, 11 Sep 2010 12:45:59 +0000 (12:45 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@996136 13f79535-47bb-0310-9956-ffa450edef68

src/documentation/content/xdocs/status.xml
src/java/org/apache/poi/hssf/model/InternalWorkbook.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
src/testcases/org/apache/poi/ss/usermodel/BaseTestNamedRange.java

index 193752ed3ab948aa54ea785117e1e771ff6d3351..a837169ed3a8c3a5be578a5215210e956af4d105 100644 (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>
index 1ac6a2a3755ce0b3729db5083a5b90e93d421853..28b6ac6263eaa36f4a5a48d1f93604586aacadfa 100644 (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 + ")");
         }
index 42ce4bcb87c743e177b408e7856dfb521b1c1c94..8ae7f9a8587b3c5b5b8e440073b95518aada4575 100644 (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;
     }
index a8b37606261818d4530a4b9a06dc5c1b609a6395..d2518effb1a136357061760c0e5e63295192ed2d 100644 (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());
+        }
+
+    }
 }