diff --git a/src/documentation/content/xdocs/changes.xml b/src/documentation/content/xdocs/changes.xml index a295fdb22..e0fdf3966 100644 --- a/src/documentation/content/xdocs/changes.xml +++ b/src/documentation/content/xdocs/changes.xml @@ -37,6 +37,7 @@ + 44921 - allow Ptg.writeBytes() to be called on relative ref Ptgs (RefN* and AreaN*) 44914 - Fix/suppress warning message "WARN. Unread n bytes of record 0xNN" 44892 - made HSSFWorkbook.getSheet(String) case insensitive 44886] - Correctly process PICT metafile in EscherMetafileBlip diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index f97a4d7f2..f1a5cd1d8 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 44921 - allow Ptg.writeBytes() to be called on relative ref Ptgs (RefN* and AreaN*) 44914 - Fix/suppress warning message "WARN. Unread n bytes of record 0xNN" 44892 - made HSSFWorkbook.getSheet(String) case insensitive 44886] - Correctly process PICT metafile in EscherMetafileBlip diff --git a/src/java/org/apache/poi/hssf/record/SharedFormulaRecord.java b/src/java/org/apache/poi/hssf/record/SharedFormulaRecord.java index a7715474a..2b0c50d12 100755 --- a/src/java/org/apache/poi/hssf/record/SharedFormulaRecord.java +++ b/src/java/org/apache/poi/hssf/record/SharedFormulaRecord.java @@ -33,7 +33,7 @@ import org.apache.poi.hssf.record.formula.*; * @author Danny Mui at apache dot org */ 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_2_last_row; @@ -186,6 +186,16 @@ public final class SharedFormulaRecord extends Record { * counter part */ 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(); if (ptgs != null) @@ -265,7 +275,7 @@ public final class SharedFormulaRecord extends Record { throw new RuntimeException("Shared Formula Conversion: Coding Error"); } } - + private static int fixupRelativeColumn(int currentcolumn, int column, boolean relative) { if(relative) { // mask out upper bits to produce 'wrapping' at column 256 ("IV") diff --git a/src/java/org/apache/poi/hssf/record/formula/AreaNAPtg.java b/src/java/org/apache/poi/hssf/record/formula/AreaNAPtg.java index 6b0eb908a..bf3ebce87 100644 --- a/src/java/org/apache/poi/hssf/record/formula/AreaNAPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/AreaNAPtg.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -16,19 +15,9 @@ limitations under the License. ==================================================================== */ -/* - * AreaPtg.java - * - * Created on November 17, 2001, 9:30 PM - */ 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.util.AreaReference; -import org.apache.poi.hssf.util.CellReference; 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) */ -public class AreaNAPtg - extends AreaPtg +public final class AreaNAPtg extends AreaPtg { public final static short sid = 0x6D; @@ -50,20 +38,16 @@ public class AreaNAPtg 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() { return "AreaNAPtg"; } 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() { - throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); + throw notImplemented(); } } diff --git a/src/java/org/apache/poi/hssf/record/formula/AreaNPtg.java b/src/java/org/apache/poi/hssf/record/formula/AreaNPtg.java index 71e413fea..b5e1ca490 100644 --- a/src/java/org/apache/poi/hssf/record/formula/AreaNPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/AreaNPtg.java @@ -36,8 +36,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; * @author Jason Height (jheight at chariot dot net dot au) */ -public class AreaNPtg - extends AreaPtg +public final class AreaNPtg extends AreaPtg { public final static short sid = 0x2D; @@ -50,23 +49,16 @@ public class AreaNPtg 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() { return "AreaNPtg"; } 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() { - throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); + throw notImplemented(); } } diff --git a/src/java/org/apache/poi/hssf/record/formula/AreaNVPtg.java b/src/java/org/apache/poi/hssf/record/formula/AreaNVPtg.java index 2ebf01982..d5f0c38cc 100644 --- a/src/java/org/apache/poi/hssf/record/formula/AreaNVPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/AreaNVPtg.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -16,19 +15,9 @@ limitations under the License. ==================================================================== */ -/* - * AreaPtg.java - * - * Created on November 17, 2001, 9:30 PM - */ 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.util.AreaReference; -import org.apache.poi.hssf.util.CellReference; import org.apache.poi.hssf.usermodel.HSSFWorkbook; /** @@ -36,10 +25,7 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook; * @author andy * @author Jason Height (jheight at chariot dot net dot au) */ - -public class AreaNVPtg - extends AreaPtg -{ +public final class AreaNVPtg extends AreaPtg { public final static short sid = 0x4D; protected AreaNVPtg() { @@ -51,20 +37,16 @@ public class AreaNVPtg 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() { return "AreaNVPtg"; } 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() { - throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); + throw notImplemented(); } } diff --git a/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java b/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java index 27e4d1759..90be1974f 100644 --- a/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/AreaPtg.java @@ -15,7 +15,6 @@ limitations under the License. ==================================================================== */ - package org.apache.poi.hssf.record.formula; import org.apache.poi.util.LittleEndian; @@ -32,10 +31,15 @@ import org.apache.poi.hssf.record.RecordInputStream; * @author andy * @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; private final static int SIZE = 9; /** zero based, unsigned 16 bit */ diff --git a/src/java/org/apache/poi/hssf/record/formula/RefNAPtg.java b/src/java/org/apache/poi/hssf/record/formula/RefNAPtg.java index 6f18e4b94..ec09a16ab 100644 --- a/src/java/org/apache/poi/hssf/record/formula/RefNAPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/RefNAPtg.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -16,26 +15,16 @@ limitations under the License. ==================================================================== */ -/* - * ValueReferencePtg.java - * - * Created on November 21, 2001, 5:27 PM - */ 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.util.CellReference; import org.apache.poi.hssf.usermodel.HSSFWorkbook; /** * RefNAPtg * @author Jason Height (jheight at chariot dot net dot au) */ - -public class RefNAPtg extends ReferencePtg +public final class RefNAPtg extends ReferencePtg { public final static byte sid = 0x6C; @@ -48,21 +37,16 @@ public class RefNAPtg extends ReferencePtg 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() { return "RefNAPtg"; } 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() { - throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); + throw notImplemented(); } } diff --git a/src/java/org/apache/poi/hssf/record/formula/RefNPtg.java b/src/java/org/apache/poi/hssf/record/formula/RefNPtg.java index e7522e7e5..a80d29f6d 100644 --- a/src/java/org/apache/poi/hssf/record/formula/RefNPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/RefNPtg.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -16,25 +15,16 @@ limitations under the License. ==================================================================== */ -/* - * RefNPtg.java - * - */ 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.util.CellReference; import org.apache.poi.hssf.usermodel.HSSFWorkbook; /** * RefNPtg * @author Jason Height (jheight at apache dot com) */ - -public class RefNPtg extends ReferencePtg +public final class RefNPtg extends ReferencePtg { public final static byte sid = 0x2C; @@ -49,21 +39,16 @@ public class RefNPtg extends ReferencePtg 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() { return "RefNPtg"; } 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() { - throw new RuntimeException("Coding Error: This method should never be called. This ptg should be converted"); + throw notImplemented(); } } diff --git a/src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java b/src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java index 3df731c7a..5fc7eaf8a 100644 --- a/src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/ReferencePtg.java @@ -30,8 +30,20 @@ import org.apache.poi.hssf.record.RecordInputStream; * @author Andrew C. Oliver (acoliver@apache.org) * @author Jason Height (jheight at chariot dot net dot au) */ - 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; public final static byte sid = 0x24; private final static int MAX_ROW_NUMBER = 65536; diff --git a/src/testcases/org/apache/poi/hssf/data/ex44921-21902.xls b/src/testcases/org/apache/poi/hssf/data/ex44921-21902.xls new file mode 100644 index 000000000..d0fbf3cab Binary files /dev/null and b/src/testcases/org/apache/poi/hssf/data/ex44921-21902.xls differ diff --git a/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java b/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java index 226b14400..0bddecd3f 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/TestReferencePtg.java @@ -1,4 +1,3 @@ - /* ==================================================================== Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with @@ -18,20 +17,22 @@ 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.HSSFWorkbook; /** * Tests for {@link ReferencePtg}. */ -public class TestReferencePtg extends AbstractPtgTestCase -{ +public final class TestReferencePtg extends TestCase { /** * Tests reading a file containing this ptg. */ - public void testReading() throws Exception - { - HSSFWorkbook workbook = loadWorkbook("ReferencePtg.xls"); + public void testReading() { + HSSFWorkbook workbook = HSSFTestDataSamples.openSampleWorkbook("ReferencePtg.xls"); HSSFSheet sheet = workbook.getSheetAt(0); // First row @@ -72,6 +73,18 @@ public class TestReferencePtg extends AbstractPtgTestCase assertEquals("Wrong formula string for reference", "A32770", 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; + } + } } -