]> source.dussan.org Git - poi.git/commitdiff
Fix for bug 27272 : Unknown Ptg 3C and 3D
authorAvik Sengupta <avik@apache.org>
Thu, 19 May 2005 14:56:45 +0000 (14:56 +0000)
committerAvik Sengupta <avik@apache.org>
Thu, 19 May 2005 14:56:45 +0000 (14:56 +0000)
by Patrick Luby, thanks!
PR:
Obtained from:
Submitted by:
Reviewed by:

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@353691 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/NameRecord.java
src/java/org/apache/poi/hssf/record/formula/DeletedArea3DPtg.java [new file with mode: 0644]
src/java/org/apache/poi/hssf/record/formula/DeletedRef3DPtg.java [new file with mode: 0644]
src/java/org/apache/poi/hssf/record/formula/Ptg.java
src/testcases/org/apache/poi/hssf/data/27272_1.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/data/27272_2.xls [new file with mode: 0644]
src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java

index 9de03bc458ff170dedf16b1969f5b448e03a9573..06277f202f5d53339cf21a36dd3958bb04294651 100644 (file)
@@ -23,6 +23,8 @@ import java.util.Stack;
 
 import org.apache.poi.hssf.model.Workbook;
 import org.apache.poi.hssf.record.formula.Area3DPtg;
+import org.apache.poi.hssf.record.formula.DeletedArea3DPtg;
+import org.apache.poi.hssf.record.formula.DeletedRef3DPtg;
 import org.apache.poi.hssf.record.formula.Ptg;
 import org.apache.poi.hssf.record.formula.Ref3DPtg;
 import org.apache.poi.hssf.util.RangeAddress;
@@ -664,7 +666,7 @@ public class NameRecord extends Record {
      * @return area reference
      */
     public String getAreaReference(Workbook book){
-        if (field_13_name_definition == null || field_13_name_definition.isEmpty()) return "#REF!";
+        if (field_13_name_definition == null || field_13_name_definition.isEmpty()) return "Error";
         Ptg ptg = (Ptg) field_13_name_definition.peek();
         String result = "";
 
@@ -673,7 +675,8 @@ public class NameRecord extends Record {
 
         } else if (ptg.getClass() == Ref3DPtg.class){
             result = ptg.toFormulaString(book);
-        }
+        } else if (ptg.getClass() == DeletedArea3DPtg.class || ptg.getClass() == DeletedRef3DPtg.class) {
+               result = "#REF!"   ;     }
 
         return result;
     }
diff --git a/src/java/org/apache/poi/hssf/record/formula/DeletedArea3DPtg.java b/src/java/org/apache/poi/hssf/record/formula/DeletedArea3DPtg.java
new file mode 100644 (file)
index 0000000..5fe9de6
--- /dev/null
@@ -0,0 +1,41 @@
+/* ====================================================================
+   Copyright 2003-2005   Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+package org.apache.poi.hssf.record.formula;
+
+/**
+ * Title:        Deleted Area 3D Ptg - 3D referecnce (Sheet + Area)<P>
+ * Description:  Defined a area in Extern Sheet. <P>
+ * REFERENCE:  <P>
+ * @author Patrick Luby
+ * @version 1.0-pre
+ */
+
+public class DeletedArea3DPtg extends Area3DPtg
+{
+       public final static byte sid = 0x3d;
+
+    /** Creates new DeletedArea3DPtg */
+    public DeletedArea3DPtg( String arearef, short externIdx )
+    {
+        super(arearef, externIdx);
+    }
+
+    public DeletedArea3DPtg( byte[] data, int offset )
+    {
+        super(data, offset);
+    }
+}
diff --git a/src/java/org/apache/poi/hssf/record/formula/DeletedRef3DPtg.java b/src/java/org/apache/poi/hssf/record/formula/DeletedRef3DPtg.java
new file mode 100644 (file)
index 0000000..d64b13a
--- /dev/null
@@ -0,0 +1,39 @@
+/* ====================================================================
+   Copyright 2003-2005   Apache Software Foundation
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+==================================================================== */
+
+
+package org.apache.poi.hssf.record.formula;
+
+/**
+ * Title:        Deleted Reference 3D Ptg <P>
+ * Description:  Defined a cell in extern sheet. <P>
+ * REFERENCE:  <P>
+ * @author Patrick Luby
+ * @version 1.0-pre
+ */
+
+public class DeletedRef3DPtg extends Ref3DPtg {
+    public final static byte sid  = 0x3c;
+
+    /** Creates new DeletedRef3DPtg */
+    public DeletedRef3DPtg(byte[] data, int offset) {
+        super(data, offset);
+    }
+
+    public DeletedRef3DPtg(String cellref, short externIdx ) {
+        super(cellref, externIdx);
+    }
+}
index 73355128f01765b69dda7252a95ca7e725aa5d73..668bc709da57ad7a1d3519a063e504fd484f5b47 100644 (file)
@@ -260,6 +260,20 @@ public abstract class Ptg
                 retval = new Ref3DPtg(data, offset);
                 break;
                 
+            case DeletedArea3DPtg.sid :      // 0x3c     
+            case DeletedArea3DPtg.sid+0x20 : // 0x5c     
+            case DeletedArea3DPtg.sid+0x40 : // 0x7c     
+
+                retval = new DeletedArea3DPtg(data, offset);
+                break;
+
+            case DeletedRef3DPtg.sid:      // 0x3d      
+            case DeletedRef3DPtg.sid+0x20: // 0x5d     
+            case DeletedRef3DPtg.sid+0x40: // 0x7d     
+
+                retval = new DeletedRef3DPtg(data, offset);
+                break;
+                
             case MissingArgPtg.sid:
                 retval = new MissingArgPtg(data,offset);
                 break;
diff --git a/src/testcases/org/apache/poi/hssf/data/27272_1.xls b/src/testcases/org/apache/poi/hssf/data/27272_1.xls
new file mode 100644 (file)
index 0000000..1715db8
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/27272_1.xls differ
diff --git a/src/testcases/org/apache/poi/hssf/data/27272_2.xls b/src/testcases/org/apache/poi/hssf/data/27272_2.xls
new file mode 100644 (file)
index 0000000..3e69928
Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/27272_2.xls differ
index 9fe7c5e67eb3eeaed28bdbbabc21a2240e8ac892..26f6cccb3a149f5507fec0303c8730192d928a0f 100644 (file)
@@ -1094,6 +1094,32 @@ extends TestCase {
         File file = TempFile.createTempFile("testComplexSheetRefs",".xls");
         sb.write(new FileOutputStream(file));
     }
+    
+       /*Unknown Ptg 3C*/
+       public void test27272_1() throws Exception {
+               String readFilename = System.getProperty("HSSF.testdata.path"); 
+               File inFile = new File(readFilename+"/27272_1.xls");
+               FileInputStream in = new FileInputStream(inFile);
+               HSSFWorkbook wb = new HSSFWorkbook(in);
+               wb.getSheetAt(0);
+               assertEquals("Reference for named range ", "#REF!",wb.getNameAt(0).getReference());
+               File outF = File.createTempFile("bug27272_1",".xls");
+               wb.write(new FileOutputStream(outF));
+               System.out.println("Open "+outF.getAbsolutePath()+" in Excel");
+       }
+       /*Unknown Ptg 3D*/
+       public void test27272_2() throws Exception {
+               String readFilename = System.getProperty("HSSF.testdata.path"); 
+               File inFile = new File(readFilename+"/27272_2.xls");
+               FileInputStream in = new FileInputStream(inFile);
+               HSSFWorkbook wb = new HSSFWorkbook(in);
+               assertEquals("Reference for named range ", "#REF!",wb.getNameAt(0).getReference());
+               File outF = File.createTempFile("bug27272_2",".xls");
+               wb.write(new FileOutputStream(outF));
+               System.out.println("Open "+outF.getAbsolutePath()+" in Excel");
+       }
+    
+    
     public static void main(String [] args) {
         System.out
         .println("Testing org.apache.poi.hssf.usermodel.TestFormulas");