44921 - allow Ptg.writeBytes() to be called on relative ref Ptgs (RefN* and AreaN*)

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@652934 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-05-02 22:36:49 +00:00
parent 45095a5d06
commit 9e6f2816c3
12 changed files with 70 additions and 102 deletions

View File

@ -37,6 +37,7 @@
<!-- Don't forget to update status.xml too! --> <!-- Don't forget to update status.xml too! -->
<release version="3.1-beta2" date="2008-05-??"> <release version="3.1-beta2" date="2008-05-??">
<action dev="POI-DEVELOPERS" type="fix">44921 - allow Ptg.writeBytes() to be called on relative ref Ptgs (RefN* and AreaN*)</action>
<action dev="POI-DEVELOPERS" type="fix">44914 - Fix/suppress warning message "WARN. Unread n bytes of record 0xNN"</action> <action dev="POI-DEVELOPERS" type="fix">44914 - Fix/suppress warning message "WARN. Unread n bytes of record 0xNN"</action>
<action dev="POI-DEVELOPERS" type="fix">44892 - made HSSFWorkbook.getSheet(String) case insensitive</action> <action dev="POI-DEVELOPERS" type="fix">44892 - made HSSFWorkbook.getSheet(String) case insensitive</action>
<action dev="POI-DEVELOPERS" type="fix">44886] - Correctly process PICT metafile in EscherMetafileBlip</action> <action dev="POI-DEVELOPERS" type="fix">44886] - Correctly process PICT metafile in EscherMetafileBlip</action>

View File

@ -34,6 +34,7 @@
<!-- Don't forget to update changes.xml too! --> <!-- Don't forget to update changes.xml too! -->
<changes> <changes>
<release version="3.1-beta2" date="2008-05-??"> <release version="3.1-beta2" date="2008-05-??">
<action dev="POI-DEVELOPERS" type="fix">44921 - allow Ptg.writeBytes() to be called on relative ref Ptgs (RefN* and AreaN*)</action>
<action dev="POI-DEVELOPERS" type="fix">44914 - Fix/suppress warning message "WARN. Unread n bytes of record 0xNN"</action> <action dev="POI-DEVELOPERS" type="fix">44914 - Fix/suppress warning message "WARN. Unread n bytes of record 0xNN"</action>
<action dev="POI-DEVELOPERS" type="fix">44892 - made HSSFWorkbook.getSheet(String) case insensitive</action> <action dev="POI-DEVELOPERS" type="fix">44892 - made HSSFWorkbook.getSheet(String) case insensitive</action>
<action dev="POI-DEVELOPERS" type="fix">44886] - Correctly process PICT metafile in EscherMetafileBlip</action> <action dev="POI-DEVELOPERS" type="fix">44886] - Correctly process PICT metafile in EscherMetafileBlip</action>

View File

@ -33,7 +33,7 @@ import org.apache.poi.hssf.record.formula.*;
* @author Danny Mui at apache dot org * @author Danny Mui at apache dot org
*/ */
public final class SharedFormulaRecord extends Record { public final class SharedFormulaRecord extends Record {
public final static short sid = 0x4BC; public final static short sid = 0x4BC;
private int field_1_first_row; private int field_1_first_row;
private int field_2_last_row; private int field_2_last_row;
@ -186,6 +186,16 @@ public final class SharedFormulaRecord extends Record {
* counter part * counter part
*/ */
protected static Stack convertSharedFormulas(Stack ptgs, int formulaRow, int formulaColumn) { protected static Stack convertSharedFormulas(Stack ptgs, int formulaRow, int formulaColumn) {
if(false) {
/*
* TODO - (May-2008) Stop converting relative ref Ptgs in shared formula records.
* If/when POI writes out the workbook, this conversion makes an unnecessary diff in the BIFF records.
* Disabling this code breaks one existing junit.
* Some fix-up will be required to make Ptg.toFormulaString(HSSFWorkbook) work properly.
* That method will need 2 extra params: rowIx and colIx.
*/
return ptgs;
}
Stack newPtgStack = new Stack(); Stack newPtgStack = new Stack();
if (ptgs != null) if (ptgs != null)

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -16,19 +15,9 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
/*
* AreaPtg.java
*
* Created on November 17, 2001, 9:30 PM
*/
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
@ -36,8 +25,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
*/ */
public class AreaNAPtg public final class AreaNAPtg extends AreaPtg
extends AreaPtg
{ {
public final static short sid = 0x6D; public final static short sid = 0x6D;
@ -50,20 +38,16 @@ public class AreaNAPtg
super(in); super(in);
} }
public void writeBytes(byte [] array, int offset) {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}
public String getAreaPtgName() { public String getAreaPtgName() {
return "AreaNAPtg"; return "AreaNAPtg";
} }
public String toFormulaString(HSSFWorkbook book) public String toFormulaString(HSSFWorkbook book)
{ {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); throw notImplemented();
} }
public Object clone() { public Object clone() {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); throw notImplemented();
} }
} }

View File

@ -36,8 +36,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
*/ */
public class AreaNPtg public final class AreaNPtg extends AreaPtg
extends AreaPtg
{ {
public final static short sid = 0x2D; public final static short sid = 0x2D;
@ -50,23 +49,16 @@ public class AreaNPtg
super(in); super(in);
} }
public void writeBytes(byte [] array, int offset) {
super.writeBytes(array,offset);
//this should be a warning...there doesn't seem to be any rationale to throwing an exception here...
//this excpeiton appears to break user defined named ranges...
//throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}
public String getAreaPtgName() { public String getAreaPtgName() {
return "AreaNPtg"; return "AreaNPtg";
} }
public String toFormulaString(HSSFWorkbook book) public String toFormulaString(HSSFWorkbook book)
{ {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); throw notImplemented();
} }
public Object clone() { public Object clone() {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); throw notImplemented();
} }
} }

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -16,19 +15,9 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
/*
* AreaPtg.java
*
* Created on November 17, 2001, 9:30 PM
*/
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.AreaReference;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
@ -36,10 +25,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
* @author andy * @author andy
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
*/ */
public final class AreaNVPtg extends AreaPtg {
public class AreaNVPtg
extends AreaPtg
{
public final static short sid = 0x4D; public final static short sid = 0x4D;
protected AreaNVPtg() { protected AreaNVPtg() {
@ -51,20 +37,16 @@ public class AreaNVPtg
super(in); super(in);
} }
public void writeBytes(byte [] array, int offset) {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}
public String getAreaPtgName() { public String getAreaPtgName() {
return "AreaNVPtg"; return "AreaNVPtg";
} }
public String toFormulaString(HSSFWorkbook book) public String toFormulaString(HSSFWorkbook book)
{ {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); throw notImplemented();
} }
public Object clone() { public Object clone() {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); throw notImplemented();
} }
} }

View File

@ -15,7 +15,6 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
@ -32,10 +31,15 @@ import org.apache.poi.hssf.record.RecordInputStream;
* @author andy * @author andy
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
*/ */
public class AreaPtg extends Ptg implements AreaI {
/**
* TODO - (May-2008) fix subclasses of AreaPtg 'AreaN~' which are used in shared formulas.
* see similar comment in ReferencePtg
*/
protected final RuntimeException notImplemented() {
return new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}
public class AreaPtg
extends Ptg implements AreaI
{
public final static short sid = 0x25; public final static short sid = 0x25;
private final static int SIZE = 9; private final static int SIZE = 9;
/** zero based, unsigned 16 bit */ /** zero based, unsigned 16 bit */

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -16,26 +15,16 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
/*
* ValueReferencePtg.java
*
* Created on November 21, 2001, 5:27 PM
*/
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
* RefNAPtg * RefNAPtg
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
*/ */
public final class RefNAPtg extends ReferencePtg
public class RefNAPtg extends ReferencePtg
{ {
public final static byte sid = 0x6C; public final static byte sid = 0x6C;
@ -48,21 +37,16 @@ public class RefNAPtg extends ReferencePtg
super(in); super(in);
} }
public void writeBytes(byte [] array, int offset)
{
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}
public String getRefPtgName() { public String getRefPtgName() {
return "RefNAPtg"; return "RefNAPtg";
} }
public String toFormulaString(HSSFWorkbook book) public String toFormulaString(HSSFWorkbook book)
{ {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); throw notImplemented();
} }
public Object clone() { public Object clone() {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); throw notImplemented();
} }
} }

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -16,25 +15,16 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
/*
* RefNPtg.java
*
*/
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.BitField;
import org.apache.poi.hssf.record.RecordInputStream; import org.apache.poi.hssf.record.RecordInputStream;
import org.apache.poi.hssf.util.CellReference;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
* RefNPtg * RefNPtg
* @author Jason Height (jheight at apache dot com) * @author Jason Height (jheight at apache dot com)
*/ */
public final class RefNPtg extends ReferencePtg
public class RefNPtg extends ReferencePtg
{ {
public final static byte sid = 0x2C; public final static byte sid = 0x2C;
@ -49,21 +39,16 @@ public class RefNPtg extends ReferencePtg
super(in); super(in);
} }
public void writeBytes(byte [] array, int offset)
{
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}
public String getRefPtgName() { public String getRefPtgName() {
return "RefNPtg"; return "RefNPtg";
} }
public String toFormulaString(HSSFWorkbook book) public String toFormulaString(HSSFWorkbook book)
{ {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); throw notImplemented();
} }
public Object clone() { public Object clone() {
throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); throw notImplemented();
} }
} }

View File

@ -30,8 +30,20 @@ import org.apache.poi.hssf.record.RecordInputStream;
* @author Andrew C. Oliver (acoliver@apache.org) * @author Andrew C. Oliver (acoliver@apache.org)
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
*/ */
public class ReferencePtg extends Ptg { public class ReferencePtg extends Ptg {
/**
* TODO - (May-2008) fix subclasses of ReferencePtg 'RefN~' which are used in shared formulas.
* (See bugzilla 44921)
* The 'RefN~' instances do not work properly, and are expected to be converted by
* SharedFormulaRecord.convertSharedFormulas().
* This conversion currently does not take place for formulas of named ranges, conditional
* format rules and data validation rules.
* Furthermore, conversion is probably not appropriate in those instances.
*/
protected final RuntimeException notImplemented() {
return new RuntimeException("Coding Error: This method should never be called. This ptg should be converted");
}
private final static int SIZE = 5; private final static int SIZE = 5;
public final static byte sid = 0x24; public final static byte sid = 0x24;
private final static int MAX_ROW_NUMBER = 65536; private final static int MAX_ROW_NUMBER = 65536;

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -18,20 +17,22 @@
package org.apache.poi.hssf.record.formula; package org.apache.poi.hssf.record.formula;
import junit.framework.AssertionFailedError;
import junit.framework.TestCase;
import org.apache.poi.hssf.HSSFTestDataSamples;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
/** /**
* Tests for {@link ReferencePtg}. * Tests for {@link ReferencePtg}.
*/ */
public class TestReferencePtg extends AbstractPtgTestCase public final class TestReferencePtg extends TestCase {
{
/** /**
* Tests reading a file containing this ptg. * Tests reading a file containing this ptg.
*/ */
public void testReading() throws Exception public void testReading() {
{ HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ReferencePtg.xls");
HSSFWorkbook workbook = loadWorkbook("ReferencePtg.xls");
HSSFSheet sheet = workbook.getSheetAt(0); HSSFSheet sheet = workbook.getSheetAt(0);
// First row // First row
@ -72,6 +73,18 @@ public class TestReferencePtg extends AbstractPtgTestCase
assertEquals("Wrong formula string for reference", "A32770", assertEquals("Wrong formula string for reference", "A32770",
sheet.getRow(32769).getCell((short) 1).getCellFormula()); sheet.getRow(32769).getCell((short) 1).getCellFormula());
} }
public void testBug44921() {
HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("ex44921-21902.xls");
try {
HSSFTestDataSamples.writeOutAndReadBack(wb);
} catch (RuntimeException e) {
if(e.getMessage().equals("Coding Error: This method should never be called. This ptg should be converted")) {
throw new AssertionFailedError("Identified bug 44921");
}
throw e;
}
}
} }