protected ArrayList records = null;
int preoffset = 0; // offset of the sheet in a new file
- protected int dimsloc = -1; // TODO - is it legal for dims record to be missing?
+ protected int dimsloc = -1; // TODO - remove dimsloc
protected PrintGridlinesRecord printGridlines = null;
protected GridsetRecord gridset = null;
private GutsRecord _gutsRecord;
private MergedCellsTable _mergedCellsTable;
/** always present in this POI object, not always written to Excel file */
/*package*/ColumnInfoRecordsAggregate _columnInfos;
- protected DimensionsRecord dims;
+ /** the DimensionsRecord is always present */
+ private DimensionsRecord _dimensions;
protected RowRecordsAggregate _rowsAggregate = null;
private DataValidityTable _dataValidityTable= null;
private ConditionalFormattingTable condFormatting;
records.add(retval._columnInfos);
}
- retval.dims = ( DimensionsRecord ) rec;
+ retval._dimensions = ( DimensionsRecord ) rec;
retval.dimsloc = records.size();
}
else if (rec.getSid() == DefaultColWidthRecord.sid)
records.add(rec);
}
- if (retval.dimsloc < 0) {
+ if (retval._dimensions == null) {
throw new RuntimeException("DimensionsRecord was not found");
}
retval.records = records;
public static Sheet createSheet()
{
+ // TODO - convert this method to a constructor
+
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "Sheet createsheet from scratch called");
Sheet retval = new Sheet();
records.add( retval.printGridlines );
retval.gridset = createGridset();
records.add( retval.gridset );
- records.add( retval.createGuts() );
+ retval._gutsRecord = createGuts();
+ records.add( retval._gutsRecord );
retval.defaultrowheight = createDefaultRowHeight();
records.add( retval.defaultrowheight );
records.add( retval.createWSBool() );
ColumnInfoRecordsAggregate columns = new ColumnInfoRecordsAggregate();
records.add( columns );
retval._columnInfos = columns;
- retval.dims = createDimensions();
- records.add(retval.dims);
+ retval._dimensions = createDimensions();
+ records.add(retval._dimensions);
retval.dimsloc = records.size()-1;
records.add(retval.windowTwo = retval.createWindowTwo());
retval.selection = createSelection();
if (_rowsAggregate == null)
{
_rowsAggregate = new RowRecordsAggregate();
- records.add(getDimsLoc() + 1, _rowsAggregate);
+ records.add(dimsloc + 1, _rowsAggregate);
}
}
private MergedCellsTable getMergedRecords() {
.append(lastrow).append("lastcol").append(lastcol)
.toString());
}
- dims.setFirstCol(firstcol);
- dims.setFirstRow(firstrow);
- dims.setLastCol(lastcol);
- dims.setLastRow(lastrow);
+ _dimensions.setFirstCol(firstcol);
+ _dimensions.setFirstRow(firstrow);
+ _dimensions.setLastCol(lastcol);
+ _dimensions.setLastRow(lastrow);
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "Sheet.setDimensions exiting");
}
if(log.check(POILogger.DEBUG)) {
log.log(POILogger.DEBUG, "add value record row" + row);
}
- DimensionsRecord d = ( DimensionsRecord ) records.get(getDimsLoc());
+ DimensionsRecord d = _dimensions;
if (col.getColumn() > d.getLastCol())
{
*/
public void removeValueRecord(int row, CellValueRecordInterface col) {
- log.logFormatted(POILogger.DEBUG, "remove value record row,dimsloc %,%",
- new int[]{row, dimsloc} );
+ log.logFormatted(POILogger.DEBUG, "remove value record row %",
+ new int[]{row } );
_rowsAggregate.removeCell(col);
}
checkRows();
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "addRow ");
- DimensionsRecord d = ( DimensionsRecord ) records.get(getDimsLoc());
+ DimensionsRecord d = _dimensions;
if (row.getRowNumber() >= d.getLastRow())
{
}
}
- /**
- * get the location of the DimensionsRecord (which is the last record before the value section)
- * @return location in the array of records of the DimensionsRecord
- */
-
- public int getDimsLoc()
- {
- if (log.check( POILogger.DEBUG ))
- log.log(POILogger.DEBUG, "getDimsLoc dimsloc= " + dimsloc);
- return dimsloc;
- }
-
- /**
- * in the event the record is a dimensions record, resets both the loc index and dimsloc index
- */
- public void checkDimsLoc(Record rec, int recloc) {
- if (rec.getSid() == DimensionsRecord.sid) {
- dimsloc = recloc;
- }
- }
-
/**
* @return the serialized size of this sheet
*/
import org.apache.poi.hssf.record.ColumnInfoRecord;
import org.apache.poi.hssf.record.DimensionsRecord;
import org.apache.poi.hssf.record.EOFRecord;
+import org.apache.poi.hssf.record.GutsRecord;
import org.apache.poi.hssf.record.IndexRecord;
import org.apache.poi.hssf.record.MergeCellsRecord;
import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.aggregates.ColumnInfoRecordsAggregate;
import org.apache.poi.hssf.record.aggregates.PageSettingsBlock;
import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
+import org.apache.poi.hssf.usermodel.HSSFSheet;
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.CellRangeAddress;
/**
if (false) {
// make sure that RRA and VRA are in the right place
// (Aug 2008) since the VRA is now part of the RRA, there is much less chance that
- // they could get out of order. Still, one could write serialize the sheet here,
- // and read back with EventRecordFactory to make sure...
+ // they could get out of order. Still, one could write serialize the sheet here,
+ // and read back with EventRecordFactory to make sure...
}
assertEquals(242, dbCellRecordPos);
}
return _indexRecord;
}
}
+
+ /**
+ * Checks for bug introduced around r682282-r683880 that caused a second GUTS records
+ * which in turn got the dimensions record out of alignment
+ */
+ public void testGutsRecord_bug45640() {
+
+ Sheet sheet = Sheet.createSheet();
+ sheet.addRow(new RowRecord(0));
+ sheet.addRow(new RowRecord(1));
+ sheet.groupRowRange( 0, 1, true );
+ sheet.toString();
+ List recs = sheet.getRecords();
+ int count=0;
+ for(int i=0; i< recs.size(); i++) {
+ if (recs.get(i) instanceof GutsRecord) {
+ count++;
+ }
+ }
+ if (count == 2) {
+ throw new AssertionFailedError("Identified bug 45640");
+ }
+ assertEquals(1, count);
+ }
}