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
This commit is contained in:
Avik Sengupta 2005-05-19 14:56:45 +00:00
parent 07c855ff2f
commit 668c108b82
7 changed files with 125 additions and 2 deletions

View File

@ -23,6 +23,8 @@ import java.util.Stack;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.record.formula.Area3DPtg; 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.Ptg;
import org.apache.poi.hssf.record.formula.Ref3DPtg; import org.apache.poi.hssf.record.formula.Ref3DPtg;
import org.apache.poi.hssf.util.RangeAddress; import org.apache.poi.hssf.util.RangeAddress;
@ -664,7 +666,7 @@ public class NameRecord extends Record {
* @return area reference * @return area reference
*/ */
public String getAreaReference(Workbook book){ 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(); Ptg ptg = (Ptg) field_13_name_definition.peek();
String result = ""; String result = "";
@ -673,7 +675,8 @@ public class NameRecord extends Record {
} else if (ptg.getClass() == Ref3DPtg.class){ } else if (ptg.getClass() == Ref3DPtg.class){
result = ptg.toFormulaString(book); result = ptg.toFormulaString(book);
} } else if (ptg.getClass() == DeletedArea3DPtg.class || ptg.getClass() == DeletedRef3DPtg.class) {
result = "#REF!" ; }
return result; return result;
} }

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -260,6 +260,20 @@ public abstract class Ptg
retval = new Ref3DPtg(data, offset); retval = new Ref3DPtg(data, offset);
break; 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: case MissingArgPtg.sid:
retval = new MissingArgPtg(data,offset); retval = new MissingArgPtg(data,offset);
break; break;

Binary file not shown.

Binary file not shown.

View File

@ -1094,6 +1094,32 @@ extends TestCase {
File file = TempFile.createTempFile("testComplexSheetRefs",".xls"); File file = TempFile.createTempFile("testComplexSheetRefs",".xls");
sb.write(new FileOutputStream(file)); 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) { public static void main(String [] args) {
System.out System.out
.println("Testing org.apache.poi.hssf.usermodel.TestFormulas"); .println("Testing org.apache.poi.hssf.usermodel.TestFormulas");