From a78cd8eb0a8af2d51930c5c848c743de5bbd870c Mon Sep 17 00:00:00 2001 From: Josh Micich Date: Sun, 31 Aug 2008 19:44:11 +0000 Subject: [PATCH] Partial fix for bug 45358 - parsing area refs with rows above 32767 git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@690772 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/hssf/record/formula/Area3DPtg.java | 27 ++++++------------ .../poi/hssf/model/TestFormulaParser.java | 28 ++++++++++++++++++- 2 files changed, 36 insertions(+), 19 deletions(-) diff --git a/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java b/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java index 1ccebd0a72..9d2eeac1e0 100644 --- a/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java +++ b/src/java/org/apache/poi/hssf/record/formula/Area3DPtg.java @@ -235,29 +235,20 @@ public final class Area3DPtg extends OperandPtg implements AreaI { field_5_last_column = colRelative.setBoolean( field_5_last_column, rel ); } - - /*public String getArea(){ - RangeAddress ra = new RangeAddress( getFirstColumn(),getFirstRow() + 1, getLastColumn(), getLastRow() + 1); - String result = ra.getAddress(); - - return result; - }*/ - - public void setArea( String ref ) - { + public void setArea( String ref ) { AreaReference ar = new AreaReference( ref ); CellReference frstCell = ar.getFirstCell(); CellReference lastCell = ar.getLastCell(); - setFirstRow( (short) frstCell.getRow() ); - setFirstColumn( frstCell.getCol() ); - setLastRow( (short) lastCell.getRow() ); - setLastColumn( lastCell.getCol() ); - setFirstColRelative( !frstCell.isColAbsolute() ); - setLastColRelative( !lastCell.isColAbsolute() ); - setFirstRowRelative( !frstCell.isRowAbsolute() ); - setLastRowRelative( !lastCell.isRowAbsolute() ); + setFirstRow(frstCell.getRow()); + setFirstColumn(frstCell.getCol()); + setLastRow(lastCell.getRow()); + setLastColumn(lastCell.getCol()); + setFirstColRelative(!frstCell.isColAbsolute()); + setLastColRelative(!lastCell.isColAbsolute()); + setFirstRowRelative(!frstCell.isRowAbsolute()); + setLastRowRelative(!lastCell.isRowAbsolute()); } /** diff --git a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java index 3584e37ea4..c9fea7f1e4 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java +++ b/src/testcases/org/apache/poi/hssf/model/TestFormulaParser.java @@ -24,6 +24,7 @@ import org.apache.poi.hssf.HSSFTestDataSamples; import org.apache.poi.hssf.model.FormulaParser.FormulaParseException; import org.apache.poi.hssf.record.formula.AbstractFunctionPtg; import org.apache.poi.hssf.record.formula.AddPtg; +import org.apache.poi.hssf.record.formula.AreaI; import org.apache.poi.hssf.record.formula.AreaPtg; import org.apache.poi.hssf.record.formula.AttrPtg; import org.apache.poi.hssf.record.formula.BoolPtg; @@ -836,4 +837,29 @@ public final class TestFormulaParser extends TestCase { } cell.setCellFormula("count(fp1)"); // plain cell ref, col is in range } -} + + public void testParseAreaRefHighRow_bug45358() { + Ptg[] ptgs; + AreaI aptg; + + HSSFWorkbook book = new HSSFWorkbook(); + book.createSheet("Sheet1"); + + ptgs = FormulaParser.parse("Sheet1!A10:A40000", book); + aptg = (AreaI) ptgs[0]; + if (aptg.getLastRow() == -25537) { + throw new AssertionFailedError("Identified bug 45358"); + } + assertEquals(39999, aptg.getLastRow()); + + ptgs = FormulaParser.parse("Sheet1!A10:A65536", book); + aptg = (AreaI) ptgs[0]; + assertEquals(65535, aptg.getLastRow()); + + // plain area refs should be ok too + ptgs = parseFormula("A10:A65536"); + aptg = (AreaI) ptgs[0]; + assertEquals(65535, aptg.getLastRow()); + + } +} \ No newline at end of file -- 2.39.5