From 6b710c137b210e25ff8c51ef89867e9d812d588c Mon Sep 17 00:00:00 2001 From: Yegor Kozlov Date: Tue, 26 Jun 2012 11:30:45 +0000 Subject: [PATCH] Bugzilla 53414: properly update sheet dimensions when adding column git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1353962 13f79535-47bb-0310-9956-ffa450edef68 --- src/documentation/content/xdocs/status.xml | 1 + .../apache/poi/hssf/model/InternalSheet.java | 2 +- .../org/apache/poi/hssf/model/TestSheet.java | 41 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/documentation/content/xdocs/status.xml b/src/documentation/content/xdocs/status.xml index 7ef684155f..c05e507ff6 100644 --- a/src/documentation/content/xdocs/status.xml +++ b/src/documentation/content/xdocs/status.xml @@ -34,6 +34,7 @@ + 53414 - properly update sheet dimensions when adding column Add File based constructor to OPCPackage, alongside existing String one (which constructed a File from the string internally) 53389 - Handle formatting General and @ formats even if a locale is prefixed to them 53271 - Removed unconditional asserts in SXSSF diff --git a/src/java/org/apache/poi/hssf/model/InternalSheet.java b/src/java/org/apache/poi/hssf/model/InternalSheet.java index cbacbc0ca1..3317a95349 100644 --- a/src/java/org/apache/poi/hssf/model/InternalSheet.java +++ b/src/java/org/apache/poi/hssf/model/InternalSheet.java @@ -638,7 +638,7 @@ public final class InternalSheet { } DimensionsRecord d = _dimensions; - if (col.getColumn() > d.getLastCol()) { + if (col.getColumn() >= d.getLastCol()) { d.setLastCol(( short ) (col.getColumn() + 1)); } if (col.getColumn() < d.getFirstCol()) { diff --git a/src/testcases/org/apache/poi/hssf/model/TestSheet.java b/src/testcases/org/apache/poi/hssf/model/TestSheet.java index d3248edffe..d898a999ad 100644 --- a/src/testcases/org/apache/poi/hssf/model/TestSheet.java +++ b/src/testcases/org/apache/poi/hssf/model/TestSheet.java @@ -35,6 +35,8 @@ import org.apache.poi.ss.formula.FormulaShifter; import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.util.HexRead; +import java.io.FileOutputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -773,4 +775,43 @@ public final class TestSheet extends TestCase { assertEquals(WindowTwoRecord.sid, ((Record)sheetRecords.get(2)).getSid()); assertEquals(EOFRecord.sid, ((Record)sheetRecords.get(3)).getSid()); } + + public void testSheetDimensions() throws IOException{ + InternalSheet sheet = InternalSheet.createSheet(); + DimensionsRecord dimensions = (DimensionsRecord)sheet.findFirstRecordBySid(DimensionsRecord.sid); + assertEquals(0, dimensions.getFirstCol()); + assertEquals(0, dimensions.getFirstRow()); + assertEquals(1, dimensions.getLastCol()); // plus pne + assertEquals(1, dimensions.getLastRow()); // plus pne + + RowRecord rr = new RowRecord(0); + sheet.addRow(rr); + + assertEquals(0, dimensions.getFirstCol()); + assertEquals(0, dimensions.getFirstRow()); + assertEquals(1, dimensions.getLastCol()); + assertEquals(1, dimensions.getLastRow()); + + CellValueRecordInterface cvr; + + cvr = new BlankRecord(); + cvr.setColumn((short)0); + cvr.setRow(0); + sheet.addValueRecord(0, cvr); + + assertEquals(0, dimensions.getFirstCol()); + assertEquals(0, dimensions.getFirstRow()); + assertEquals(1, dimensions.getLastCol()); + assertEquals(1, dimensions.getLastRow()); + + cvr = new BlankRecord(); + cvr.setColumn((short)1); + cvr.setRow(0); + sheet.addValueRecord(0, cvr); + + assertEquals(0, dimensions.getFirstCol()); + assertEquals(0, dimensions.getFirstRow()); + assertEquals(2, dimensions.getLastCol()); //YK: failed until Bugzilla 53414 was fixed + assertEquals(1, dimensions.getLastRow()); + } } -- 2.39.5