From: Avik Sengupta Date: Thu, 19 May 2005 14:56:45 +0000 (+0000) Subject: Fix for bug 27272 : Unknown Ptg 3C and 3D X-Git-Tag: BEFORE_RICHTEXT~78 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=51160bc098f59bc34f6459d3b378085b63183445;p=poi.git Fix for bug 27272 : Unknown Ptg 3C and 3D 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 --- diff --git a/src/java/org/apache/poi/hssf/record/NameRecord.java b/src/java/org/apache/poi/hssf/record/NameRecord.java index 9de03bc458..06277f202f 100644 --- a/src/java/org/apache/poi/hssf/record/NameRecord.java +++ b/src/java/org/apache/poi/hssf/record/NameRecord.java @@ -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 index 0000000000..5fe9de62d2 --- /dev/null +++ b/src/java/org/apache/poi/hssf/record/formula/DeletedArea3DPtg.java @@ -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)

+ * Description: Defined a area in Extern Sheet.

+ * REFERENCE:

+ * @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 index 0000000000..d64b13abb1 --- /dev/null +++ b/src/java/org/apache/poi/hssf/record/formula/DeletedRef3DPtg.java @@ -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

+ * Description: Defined a cell in extern sheet.

+ * REFERENCE:

+ * @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); + } +} diff --git a/src/java/org/apache/poi/hssf/record/formula/Ptg.java b/src/java/org/apache/poi/hssf/record/formula/Ptg.java index 73355128f0..668bc709da 100644 --- a/src/java/org/apache/poi/hssf/record/formula/Ptg.java +++ b/src/java/org/apache/poi/hssf/record/formula/Ptg.java @@ -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 index 0000000000..1715db85d3 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 index 0000000000..3e69928d55 Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/27272_2.xls differ diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java index 9fe7c5e67e..26f6cccb3a 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestFormulas.java @@ -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");