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
This commit is contained in:
Yegor Kozlov 2012-06-26 11:30:45 +00:00
parent a92c6453ab
commit 6b710c137b
3 changed files with 43 additions and 1 deletions

View File

@ -34,6 +34,7 @@
<changes>
<release version="3.9-beta1" date="2012-??-??">
<action dev="poi-developers" type="fix">53414 - properly update sheet dimensions when adding column </action>
<action dev="poi-developers" type="add">Add File based constructor to OPCPackage, alongside existing String one (which constructed a File from the string internally)</action>
<action dev="poi-developers" type="fix">53389 - Handle formatting General and @ formats even if a locale is prefixed to them</action>
<action dev="poi-developers" type="fix">53271 - Removed unconditional asserts in SXSSF</action>

View File

@ -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()) {

View File

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