-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.model;
import org.apache.poi.hssf.record.*;
* @see org.apache.poi.hssf.usermodel.HSSFSheet
* @version 1.0-pre
*/
-
-public class Sheet implements Model
-{
+public final class Sheet implements Model {
public static final short LeftMargin = 0;
public static final short RightMargin = 1;
public static final short TopMargin = 2;
protected ObjectProtectRecord objprotect = null;
protected ScenarioProtectRecord scenprotect = null;
protected PasswordRecord password = null;
- protected List condFormatting = new ArrayList();;
+ protected List condFormatting = new ArrayList();
- /** Add an UncalcedRecord if not true indicating formulas have not been calculated */
+ /** Add an UncalcedRecord if not true indicating formulas have not been calculated */
protected boolean uncalced = false;
public static final byte PANE_LOWER_RIGHT = (byte)0;
public static final byte PANE_UPPER_LEFT = (byte)3;
/**
- * Creates new Sheet with no intialization --useless at this point
+ * Creates new Sheet with no initialization --useless at this point
* @see #createSheet(List,int,int)
*/
public Sheet()
}
}
else if (rec.getSid() == UncalcedRecord.sid) {
- retval.uncalced = true;
+ retval.uncalced = true;
}
else if (rec.getSid() == DimensionsRecord.sid)
{
}
else if ( rec.getSid() == CFHeaderRecord.sid )
{
- CFRecordsAggregate cfAgg = CFRecordsAggregate.createCFAggregate(recs, k);
- retval.condFormatting.add(cfAgg);
- rec = cfAgg;
+ CFRecordsAggregate cfAgg = CFRecordsAggregate.createCFAggregate(recs, k);
+ retval.condFormatting.add(cfAgg);
+ rec = cfAgg;
}
else if ( rec.getSid() == CFRuleRecord.sid )
{
- // Skip it since it is processed by CFRecordsAggregate
- rec = null;
+ // Skip it since it is processed by CFRecordsAggregate
+ rec = null;
}
else if (rec.getSid() == ColumnInfoRecord.sid)
{
if ( isfirstrow )
{
retval.rows = new RowRecordsAggregate();
- rec = retval.rows;
+ rec = retval.rows;
isfirstrow = false;
}
retval.rows.insertRow(row);
else if ( rec.getSid() == GridsetRecord.sid )
{
retval.gridset = (GridsetRecord) rec;
- }
+ }
else if ( rec.getSid() == HeaderRecord.sid && bofEofNestingLevel == 1)
{
retval.header = (HeaderRecord) rec;
{
rec = null;
}
-
- else if ( rec.getSid() == ProtectRecord.sid )
- {
- retval.protect = (ProtectRecord) rec;
- }
- else if ( rec.getSid() == ObjectProtectRecord.sid )
- {
- retval.objprotect = (ObjectProtectRecord) rec;
- }
- else if ( rec.getSid() == ScenarioProtectRecord.sid )
- {
- retval.scenprotect = (ScenarioProtectRecord) rec;
- }
- else if ( rec.getSid() == PasswordRecord.sid )
- {
- retval.password = (PasswordRecord) rec;
- }
- else if (rec.getSid() == PageBreakRecord.HORIZONTAL_SID)
- {
- retval.rowBreaks = (PageBreakRecord)rec;
- }
- else if (rec.getSid() == PageBreakRecord.VERTICAL_SID)
- {
- retval.colBreaks = (PageBreakRecord)rec;
- }
-
+
+ else if ( rec.getSid() == ProtectRecord.sid )
+ {
+ retval.protect = (ProtectRecord) rec;
+ }
+ else if ( rec.getSid() == ObjectProtectRecord.sid )
+ {
+ retval.objprotect = (ObjectProtectRecord) rec;
+ }
+ else if ( rec.getSid() == ScenarioProtectRecord.sid )
+ {
+ retval.scenprotect = (ScenarioProtectRecord) rec;
+ }
+ else if ( rec.getSid() == PasswordRecord.sid )
+ {
+ retval.password = (PasswordRecord) rec;
+ }
+ else if (rec.getSid() == PageBreakRecord.HORIZONTAL_SID)
+ {
+ retval.rowBreaks = (PageBreakRecord)rec;
+ }
+ else if (rec.getSid() == PageBreakRecord.VERTICAL_SID)
+ {
+ retval.colBreaks = (PageBreakRecord)rec;
+ }
+
if (rec != null)
{
records.add(rec);
/**
* Clones the low level records of this sheet and returns the new sheet instance.
* This method is implemented by adding methods for deep cloning to all records that
- * can be added to a sheet. The <b>Record</b> object does not implement cloneable.
+ * can be added to a sheet. The <b>Record</b> object does not implement cloneable.
* When adding a new record, implement a public clone method if and only if the record
- * belongs to a sheet.
+ * belongs to a sheet.
*/
public Sheet cloneSheet()
{
ValueRecordsAggregate vrAgg = (ValueRecordsAggregate)rec;
for (Iterator cellIter = vrAgg.getIterator();cellIter.hasNext();) {
Record valRec = (Record)cellIter.next();
-
+
if (valRec instanceof FormulaRecordAggregate) {
FormulaRecordAggregate fmAgg = (FormulaRecordAggregate)valRec;
Record fmAggRec = fmAgg.getFormulaRecord();
records.add(retval.rowBreaks);
retval.colBreaks = new PageBreakRecord(PageBreakRecord.VERTICAL_SID);
records.add(retval.colBreaks);
-
+
retval.header = (HeaderRecord) retval.createHeader();
- records.add( retval.header );
+ records.add( retval.header );
retval.footer = (FooterRecord) retval.createFooter();
records.add( retval.footer );
records.add( retval.createHCenter() );
retval.dimsloc = records.size()-1;
records.add(retval.windowTwo = retval.createWindowTwo());
retval.setLoc(records.size() - 1);
- retval.selection =
+ retval.selection =
(SelectionRecord) retval.createSelection();
records.add(retval.selection);
- retval.protect = (ProtectRecord) retval.createProtect();
- records.add(retval.protect);
+ retval.protect = (ProtectRecord) retval.createProtect();
+ records.add(retval.protect);
records.add(retval.createEOF());
}
}
- //public int addMergedRegion(short rowFrom, short colFrom, short rowTo,
- public int addMergedRegion(int rowFrom, short colFrom, int rowTo,
- short colTo)
- {
- // Validate input
- if(rowTo < rowFrom) {
- throw new IllegalArgumentException("The row to ("+rowTo+") must be >= the row from ("+rowFrom+")");
- }
- if(colTo < colFrom) {
- throw new IllegalArgumentException("The col to ("+colTo+") must be >= the col from ("+colFrom+")");
- }
-
+ public int addMergedRegion(int rowFrom, short colFrom, int rowTo, short colTo) {
+ // Validate input
+ if (rowTo < rowFrom) {
+ throw new IllegalArgumentException("The 'to' row (" + rowTo
+ + ") must not be less than the 'from' row (" + rowFrom + ")");
+ }
+ if (colTo < colFrom) {
+ throw new IllegalArgumentException("The 'to' col (" + colTo
+ + ") must not be less than the 'from' col (" + colFrom + ")");
+ }
+
if (merged == null || merged.getNumAreas() == 1027)
{
merged = ( MergeCellsRecord ) createMergedCells();
- mergedRecords.add(merged);
+ mergedRecords.add(merged);
records.add(records.size() - 1, merged);
}
merged.addArea(rowFrom, colFrom, rowTo, colTo);
- return numMergedRegions++;
+ return numMergedRegions++;
}
public void removeMergedRegion(int index)
//safety checks
if (index >= numMergedRegions || mergedRecords.size() == 0)
return;
-
+
int pos = 0;
int startNumRegions = 0;
-
+
//optimisation for current record
if (numMergedRegions - index < merged.getNumAreas())
{
pos = mergedRecords.size() - 1;
- startNumRegions = numMergedRegions - merged.getNumAreas();
+ startNumRegions = numMergedRegions - merged.getNumAreas();
}
else
{
pos = n;
break;
}
- startNumRegions += record.getNumAreas();
+ startNumRegions += record.getNumAreas();
}
}
numMergedRegions--;
if (rec.getNumAreas() == 0)
{
- mergedRecords.remove(pos);
- //get rid of the record from the sheet
- records.remove(merged);
+ mergedRecords.remove(pos);
+ //get rid of the record from the sheet
+ records.remove(merged);
if (merged == rec) {
- //pull up the LAST record for operations when we finally
- //support continue records for mergedRegions
- if (mergedRecords.size() > 0) {
- merged = (MergeCellsRecord) mergedRecords.get(mergedRecords.size() - 1);
- } else {
- merged = null;
- }
+ //pull up the LAST record for operations when we finally
+ //support continue records for mergedRegions
+ if (mergedRecords.size() > 0) {
+ merged = (MergeCellsRecord) mergedRecords.get(mergedRecords.size() - 1);
+ } else {
+ merged = null;
+ }
}
}
}
//safety checks
if (index >= numMergedRegions || mergedRecords.size() == 0)
return null;
-
+
int pos = 0;
int startNumRegions = 0;
-
+
//optimisation for current record
if (numMergedRegions - index < merged.getNumAreas())
{
pos = n;
break;
}
- startNumRegions += record.getNumAreas();
+ startNumRegions += record.getNumAreas();
}
}
return ((MergeCellsRecord) mergedRecords.get(pos)).getAreaAt(index - startNumRegions);
// Find correct position to add new CF record
private int findConditionalFormattingPosition()
{
- // This is default.
- // If the algorithm does not find the right position,
- // this one will be used (this is a position before EOF record)
- int index = records.size()-2;
-
- for( int i=index; i>=0; i-- )
- {
- Record rec = (Record)records.get(i);
- short sid = rec.getSid();
-
- // CFRecordsAggregate records already exist, just add to the end
- if (rec instanceof CFRecordsAggregate) { return i+1; }
-
- if( sid == (short)0x00ef ) { return i+1; }// PHONETICPR
- if( sid == (short)0x015f ) { return i+1; }// LABELRANGES
- if( sid == MergeCellsRecord.sid ) { return i+1; }
- if( sid == (short)0x0099 ) { return i+1; }// STANDARDWIDTH
- if( sid == SelectionRecord.sid ) { return i+1; }
- if( sid == PaneRecord.sid ) { return i+1; }
- if( sid == SCLRecord.sid ) { return i+1; }
- if( sid == WindowTwoRecord.sid ) { return i+1; }
- }
-
- return index;
+ // This is default.
+ // If the algorithm does not find the right position,
+ // this one will be used (this is a position before EOF record)
+ int index = records.size()-2;
+
+ for( int i=index; i>=0; i-- )
+ {
+ Record rec = (Record)records.get(i);
+ short sid = rec.getSid();
+
+ // CFRecordsAggregate records already exist, just add to the end
+ if (rec instanceof CFRecordsAggregate) { return i+1; }
+
+ if( sid == (short)0x00ef ) { return i+1; }// PHONETICPR
+ if( sid == (short)0x015f ) { return i+1; }// LABELRANGES
+ if( sid == MergeCellsRecord.sid ) { return i+1; }
+ if( sid == (short)0x0099 ) { return i+1; }// STANDARDWIDTH
+ if( sid == SelectionRecord.sid ) { return i+1; }
+ if( sid == PaneRecord.sid ) { return i+1; }
+ if( sid == SCLRecord.sid ) { return i+1; }
+ if( sid == WindowTwoRecord.sid ) { return i+1; }
+ }
+
+ return index;
}
public int addConditionalFormatting(CFRecordsAggregate cfAggregate)
{
- int index = findConditionalFormattingPosition();
- records.add(index, cfAggregate);
- condFormatting.add(cfAggregate);
- return condFormatting.size()-1;
+ int index = findConditionalFormattingPosition();
+ records.add(index, cfAggregate);
+ condFormatting.add(cfAggregate);
+ return condFormatting.size()-1;
}
public void removeConditionalFormatting(int index)
{
if (index >= 0 && index <= condFormatting.size()-1 )
{
- CFRecordsAggregate cfAggregate = getCFRecordsAggregateAt(index);
- records.remove(cfAggregate);
- condFormatting.remove(index);
+ CFRecordsAggregate cfAggregate = getCFRecordsAggregateAt(index);
+ records.remove(cfAggregate);
+ condFormatting.remove(index);
}
}
-
+
public CFRecordsAggregate getCFRecordsAggregateAt(int index)
{
if (index >= 0 && index <= condFormatting.size()-1 )
{
- return (CFRecordsAggregate) condFormatting.get(index);
+ return (CFRecordsAggregate) condFormatting.get(index);
}
return null;
}
-
+
public int getNumConditionalFormattings()
{
- return condFormatting.size();
+ return condFormatting.size();
}
/**
*
* @see org.apache.poi.hssf.record.DimensionsRecord
*/
-
- //public void setDimensions(short firstrow, short firstcol, short lastrow,
public void setDimensions(int firstrow, short firstcol, int lastrow,
short lastcol)
{
/**
* set the locator for where we should look for the next value record. The
- * algorythm will actually start here and find the correct location so you
+ * algorithm will actually start here and find the correct location so you
* can set this to 0 and watch performance go down the tubes but it will work.
* After a value is set this is automatically advanced. Its also set by the
* create method. So you probably shouldn't mess with this unless you have
for (int k = 0; k < records.size(); k++)
{
Record record = (( Record ) records.get(k));
-
+
// Don't write out UncalcedRecord entries, as
// we handle those specially just below
if (record instanceof UncalcedRecord) {
- continue;
+ continue;
}
-
+
// Once the rows have been found in the list of records, start
// writing out the blocked row information. This includes the DBCell references
if (record instanceof RowRecordsAggregate) {
} else {
pos += record.serialize(pos, data ); // rec.length;
}
-
+
// If the BOF record was just serialized then add the IndexRecord
if (record.getSid() == BOFRecord.sid) {
// Add an optional UncalcedRecord
if (uncalced) {
- UncalcedRecord rec = new UncalcedRecord();
- pos += rec.serialize(pos, data);
+ UncalcedRecord rec = new UncalcedRecord();
+ pos += rec.serialize(pos, data);
}
//Can there be more than one BOF for a sheet? If not then we can
//remove this guard. So be safe it is left here.
log.log(POILogger.DEBUG, "Sheet.serialize returning ");
return pos-offset;
}
-
+
private int serializeIndexRecord(final int BOFRecordIndex, final int offset, byte[] data) {
IndexRecord index = new IndexRecord();
index.setFirstRow(rows.getFirstRowNum());
}
return index.serialize(offset, data);
}
-
+
/**
* Create a row record. (does not add it to the records contained in this sheet)
* @return LabelSSTRecord newly created containing your SST Index, row,col.
* @see org.apache.poi.hssf.record.SSTRecord
*/
-
- //public LabelSSTRecord createLabelSST(short row, short col, int index)
public LabelSSTRecord createLabelSST(int row, short col, int index)
{
log.logFormatted(POILogger.DEBUG, "create labelsst row,col,index %,%,%",
*
* @return NumberRecord for that row, col containing that value as added to the sheet
*/
-
- //public NumberRecord createNumber(short row, short col, double value)
public NumberRecord createNumber(int row, short col, double value)
{
log.logFormatted(POILogger.DEBUG, "create number row,col,value %,%,%",
});
NumberRecord rec = new NumberRecord();
- //rec.setRow(( short ) row);
rec.setRow(row);
rec.setColumn(col);
rec.setValue(value);
* @param row - the row the BlankRecord is a member of
* @param col - the column the BlankRecord is a member of
*/
-
- //public BlankRecord createBlank(short row, short col)
public BlankRecord createBlank(int row, short col)
{
- //log.logFormatted(POILogger.DEBUG, "create blank row,col %,%", new short[]
log.logFormatted(POILogger.DEBUG, "create blank row,col %,%", new int[]
{
row, col
});
BlankRecord rec = new BlankRecord();
- //rec.setRow(( short ) row);
rec.setRow(row);
rec.setColumn(col);
rec.setXFIndex(( short ) 0x0f);
* @param formula - a String representing the formula. To be parsed to PTGs
* @return bogus/useless formula record
*/
-
- //public FormulaRecord createFormula(short row, short col, String formula)
public FormulaRecord createFormula(int row, short col, String formula)
{
log.logFormatted(POILogger.DEBUG, "create formula row,col,formula %,%,%",
- //new short[]
new int[]
{
row, col
* @param row the row to add the cell value to
* @param col the cell value record itself.
*/
-
- //public void addValueRecord(short row, CellValueRecordInterface col)
public void addValueRecord(int row, CellValueRecordInterface col)
{
checkCells();
d.setFirstCol(col.getColumn());
}
cells.insertCell(col);
-
- /*
- * for (int k = loc; k < records.size(); k++)
- * {
- * Record rec = ( Record ) records.get(k);
- *
- * if (rec.getSid() == RowRecord.sid)
- * {
- * RowRecord rowrec = ( RowRecord ) rec;
- *
- * if (rowrec.getRowNumber() == col.getRow())
- * {
- * records.add(k + 1, col);
- * loc = k;
- * if (rowrec.getLastCol() <= col.getColumn())
- * {
- * rowrec.setLastCol((( short ) (col.getColumn() + 1)));
- * }
- * break;
- * }
- * }
- * }
- */
}
/**
* @param col - a record supporting the CellValueRecordInterface.
* @see org.apache.poi.hssf.record.CellValueRecordInterface
*/
-
- //public void removeValueRecord(short row, CellValueRecordInterface col)
public void removeValueRecord(int row, CellValueRecordInterface col)
{
checkCells();
new int[]{row, dimsloc} );
loc = dimsloc;
cells.removeCell(col);
-
- /*
- * for (int k = loc; k < records.size(); k++)
- * {
- * Record rec = ( Record ) records.get(k);
- *
- * // checkDimsLoc(rec,k);
- * if (rec.isValue())
- * {
- * CellValueRecordInterface cell =
- * ( CellValueRecordInterface ) rec;
- *
- * if ((cell.getRow() == col.getRow())
- * && (cell.getColumn() == col.getColumn()))
- * {
- * records.remove(k);
- * break;
- * }
- * }
- * }
- */
}
/**
//The ValueRecordsAggregate use a tree map underneath.
//The tree Map uses the CellValueRecordInterface as both the
//key and the value, if we dont do a remove, then
- //the previous instance of the key is retained, effectively using
+ //the previous instance of the key is retained, effectively using
//double the memory
cells.removeCell(newval);
cells.insertCell(newval);
-
- /*
- * CellValueRecordInterface oldval = getNextValueRecord();
- *
- * while (oldval != null)
- * {
- * if (oldval.isEqual(newval))
- * {
- * records.set(( short ) (getLoc() - 1), newval);
- * return;
- * }
- * oldval = getNextValueRecord();
- * }
- * addValueRecord(newval.getRow(), newval);
- * setLoc(dimsloc);
- */
}
/**
rows.insertRow(row);
- /*
- * for (int k = loc; k < records.size(); k++)
- * {
- * Record rec = ( Record ) records.get(k);
- *
- * if (rec.getSid() == IndexRecord.sid)
- * {
- * index = ( IndexRecord ) rec;
- * }
- * if (rec.getSid() == RowRecord.sid)
- * {
- * RowRecord rowrec = ( RowRecord ) rec;
- *
- * if (rowrec.getRowNumber() > row.getRowNumber())
- * {
- * records.add(k, row);
- * loc = k;
- * break;
- * }
- * }
- * if (rec.getSid() == WindowTwoRecord.sid)
- * {
- * records.add(k, row);
- * loc = k;
- * break;
- * }
- * }
- * if (index != null)
- * {
- * if (index.getLastRowAdd1() <= row.getRowNumber())
- * {
- * index.setLastRowAdd1(row.getRowNumber() + 1);
- * }
- * }
- */
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "exit addRow");
}
public void removeRow(RowRecord row)
{
checkRows();
- // IndexRecord index = null;
setLoc(getDimsLoc());
rows.removeRow(row);
-
- /*
- * for (int k = loc; k < records.size(); k++)
- * {
- * Record rec = ( Record ) records.get(k);
- *
- * // checkDimsLoc(rec,k);
- * if (rec.getSid() == RowRecord.sid)
- * {
- * RowRecord rowrec = ( RowRecord ) rec;
- *
- * if (rowrec.getRowNumber() == row.getRowNumber())
- * {
- * records.remove(k);
- * break;
- * }
- * }
- * if (rec.getSid() == WindowTwoRecord.sid)
- * {
- * break;
- * }
- * }
- */
}
/**
return null;
}
return ( CellValueRecordInterface ) valueRecIterator.next();
-
- /*
- * if (this.getLoc() < records.size())
- * {
- * for (int k = getLoc(); k < records.size(); k++)
- * {
- * Record rec = ( Record ) records.get(k);
- *
- * this.setLoc(k + 1);
- * if (rec instanceof CellValueRecordInterface)
- * {
- * return ( CellValueRecordInterface ) rec;
- * }
- * }
- * }
- * return null;
- */
- }
-
- /**
- * get the NEXT RowRecord or CellValueRecord(from LOC). The first record that
- * is a Row record or CellValueRecord(starting at LOC) will be returned.
- * <P>
- * This method is "loc" sensitive. Meaning you need to set LOC to where you
- * want it to start searching. If you don't know do this: setLoc(getDimsLoc).
- * When adding several rows you can just start at the last one by leaving loc
- * at what this sets it to. For this method, set loc to dimsloc to start with.
- * subsequent calls will return rows in (physical) sequence or NULL when you get to the end.
- *
- * @return RowRecord representing the next row record or CellValueRecordInterface
- * representing the next cellvalue or NULL if there are no more
- * @see #setLoc(int)
- *
- */
-
-/* public Record getNextRowOrValue()
- {
- POILogger.DEBUG((new StringBuffer("getNextRow loc= ")).append(loc)
- .toString());
- if (this.getLoc() < records.size())
- {
- for (int k = this.getLoc(); k < records.size(); k++)
- {
- Record rec = ( Record ) records.get(k);
-
- this.setLoc(k + 1);
- if (rec.getSid() == RowRecord.sid)
- {
- return rec;
- }
- else if (rec.isValue())
- {
- return rec;
- }
- }
- }
- return null;
}
- */
/**
* get the NEXT RowRecord (from LOC). The first record that is a Row record
return null;
}
return ( RowRecord ) rowRecIterator.next();
-
-/* if (this.getLoc() < records.size())
- {
- for (int k = this.getLoc(); k < records.size(); k++)
- {
- Record rec = ( Record ) records.get(k);
-
- this.setLoc(k + 1);
- if (rec.getSid() == RowRecord.sid)
- {
- return ( RowRecord ) rec;
- }
- }
- }*/
}
/**
* @see #setLoc(int)
*
*/
-
- //public RowRecord getRow(short rownum)
- public RowRecord getRow(int rownum)
- {
+ public RowRecord getRow(int rownum) {
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "getNextRow loc= " + loc);
return rows.getRow(rownum);
-
- /*
- * if (this.getLoc() < records.size())
- * {
- * for (int k = this.getLoc(); k < records.size(); k++)
- * {
- * Record rec = ( Record ) records.get(k);
- *
- * this.setLoc(k + 1);
- * if (rec.getSid() == RowRecord.sid)
- * {
- * if ((( RowRecord ) rec).getRowNumber() == rownum)
- * {
- * return ( RowRecord ) rec;
- * }
- * }
- * }
- * }
- */
-
- // return null;
}
/**
retval.setVersion(( short ) 0x600);
retval.setType(( short ) 0x010);
- // retval.setBuild((short)0x10d3);
retval.setBuild(( short ) 0x0dbb);
retval.setBuildYear(( short ) 1996);
retval.setHistoryBitMask(0xc1);
* @see org.apache.poi.hssf.record.ColumnInfoRecord
* @return record containing a ColumnInfoRecord
*/
-
+ // TODO change return type to ColumnInfoRecord
protected Record createColInfo()
{
return ColumnInfoRecordsAggregate.createColInfo();
public boolean isGridsPrinted()
{
- if (gridset == null) {
- gridset = (GridsetRecord)createGridset();
- //Insert the newlycreated Gridset record at the end of the record (just before the EOF)
- int loc = findFirstRecordLocBySid(EOFRecord.sid);
- records.add(loc, gridset);
- }
+ if (gridset == null) {
+ gridset = (GridsetRecord)createGridset();
+ //Insert the newlycreated Gridset record at the end of the record (just before the EOF)
+ int loc = findFirstRecordLocBySid(EOFRecord.sid);
+ records.add(loc, gridset);
+ }
return !gridset.getGridset();
}
}
return retval;
}
-
+
/**
- * get the index to the ExtendedFormatRecord "associated" with
- * the column at specified 0-based index. (In this case, an
- * ExtendedFormatRecord index is actually associated with a
+ * get the index to the ExtendedFormatRecord "associated" with
+ * the column at specified 0-based index. (In this case, an
+ * ExtendedFormatRecord index is actually associated with a
* ColumnInfoRecord which spans 1 or more columns)
* <br/>
* Returns the index to the default ExtendedFormatRecord (0xF)
* if no ColumnInfoRecord exists that includes the column
- * index specified.
+ * index specified.
* @param column
* @return index of ExtendedFormatRecord associated with
* ColumnInfoRecord that includes the column index or the
retval.setNumRefs(( short ) 0x0);
return retval;
}
-
- public short getTopRow()
+
+ public short getTopRow()
{
- return (windowTwo==null) ? (short) 0 : windowTwo.getTopRow();
+ return (windowTwo==null) ? (short) 0 : windowTwo.getTopRow();
}
-
- public void setTopRow(short topRow)
+
+ public void setTopRow(short topRow)
{
- if (windowTwo!=null)
- {
- windowTwo.setTopRow(topRow);
- }
+ if (windowTwo!=null)
+ {
+ windowTwo.setTopRow(topRow);
+ }
}
-
+
/**
* Sets the left column to show in desktop window pane.
* @param leftCol the left column to show in desktop window pane
*/
public void setLeftCol(short leftCol){
- if (windowTwo!=null)
- {
- windowTwo.setLeftCol(leftCol);
- }
+ if (windowTwo!=null)
+ {
+ windowTwo.setLeftCol(leftCol);
+ }
}
-
- public short getLeftCol()
+
+ public short getLeftCol()
{
- return (windowTwo==null) ? (short) 0 : windowTwo.getLeftCol();
+ return (windowTwo==null) ? (short) 0 : windowTwo.getLeftCol();
}
-
-
-
+
+
+
/**
* Returns the active row
*
}
return selection.getActiveCellRow();
}
-
+
/**
* Sets the active row
*
selection.setActiveCellRow(row);
}
}
-
+
/**
* Returns the active column
*
}
return selection.getActiveCellCol();
}
-
+
/**
* Sets the active column
*
}
// Add space for UncalcedRecord
if (uncalced) {
- retval += UncalcedRecord.getStaticRecordSize();
+ retval += UncalcedRecord.getStaticRecordSize();
}
-
+
return retval;
}
*/
public HeaderRecord getHeader ()
{
- return header;
+ return header;
}
/**
*/
public void setHeader (HeaderRecord newHeader)
{
- header = newHeader;
+ header = newHeader;
}
/**
*/
public FooterRecord getFooter ()
{
- return footer;
+ return footer;
}
/**
*/
public void setFooter (FooterRecord newFooter)
{
- footer = newFooter;
+ footer = newFooter;
}
/**
*/
public PrintSetupRecord getPrintSetup ()
{
- return printSetup;
+ return printSetup;
}
/**
*/
public void setPrintSetup (PrintSetupRecord newPrintSetup)
{
- printSetup = newPrintSetup;
+ printSetup = newPrintSetup;
}
/**
*/
public PrintGridlinesRecord getPrintGridlines ()
{
- return printGridlines;
+ return printGridlines;
}
/**
*/
public void setPrintGridlines (PrintGridlinesRecord newPrintGridlines)
{
- printGridlines = newPrintGridlines;
+ printGridlines = newPrintGridlines;
}
/**
* @return the size of the margin
*/
public double getMargin(short margin) {
- if (getMargins()[margin] != null)
- return margins[margin].getMargin();
- else {
- switch ( margin )
- {
- case LeftMargin:
- return .75;
- case RightMargin:
- return .75;
- case TopMargin:
- return 1.0;
- case BottomMargin:
- return 1.0;
- default :
- throw new RuntimeException( "Unknown margin constant: " + margin );
- }
- }
+ if (getMargins()[margin] != null)
+ return margins[margin].getMargin();
+ else {
+ switch ( margin )
+ {
+ case LeftMargin:
+ return .75;
+ case RightMargin:
+ return .75;
+ case TopMargin:
+ return 1.0;
+ case BottomMargin:
+ return 1.0;
+ default :
+ throw new RuntimeException( "Unknown margin constant: " + margin );
+ }
+ }
}
/**
* @param size the size of the margin
*/
public void setMargin(short margin, double size) {
- Margin m = getMargins()[margin];
- if (m == null) {
- switch ( margin )
- {
- case LeftMargin:
- m = new LeftMarginRecord();
- records.add( getDimsLoc() + 1, m );
- break;
- case RightMargin:
- m = new RightMarginRecord();
- records.add( getDimsLoc() + 1, m );
- break;
- case TopMargin:
- m = new TopMarginRecord();
- records.add( getDimsLoc() + 1, m );
- break;
- case BottomMargin:
- m = new BottomMarginRecord();
- records.add( getDimsLoc() + 1, m );
- break;
- default :
- throw new RuntimeException( "Unknown margin constant: " + margin );
- }
- margins[margin] = m;
- }
- m.setMargin( size );
+ Margin m = getMargins()[margin];
+ if (m == null) {
+ switch ( margin )
+ {
+ case LeftMargin:
+ m = new LeftMarginRecord();
+ records.add( getDimsLoc() + 1, m );
+ break;
+ case RightMargin:
+ m = new RightMarginRecord();
+ records.add( getDimsLoc() + 1, m );
+ break;
+ case TopMargin:
+ m = new TopMarginRecord();
+ records.add( getDimsLoc() + 1, m );
+ break;
+ case BottomMargin:
+ m = new BottomMarginRecord();
+ records.add( getDimsLoc() + 1, m );
+ break;
+ default :
+ throw new RuntimeException( "Unknown margin constant: " + margin );
+ }
+ margins[margin] = m;
+ }
+ m.setMargin( size );
}
public int getEofLoc()
*/
public void createFreezePane(int colSplit, int rowSplit, int topRow, int leftmostColumn )
{
- int paneLoc = findFirstRecordLocBySid(PaneRecord.sid);
- if (paneLoc != -1)
- records.remove(paneLoc);
-
+ int paneLoc = findFirstRecordLocBySid(PaneRecord.sid);
+ if (paneLoc != -1)
+ records.remove(paneLoc);
+
int loc = findFirstRecordLocBySid(WindowTwoRecord.sid);
PaneRecord pane = new PaneRecord();
pane.setX((short)colSplit);
*/
public void createSplitPane(int xSplitPos, int ySplitPos, int topRow, int leftmostColumn, int activePane )
{
- int paneLoc = findFirstRecordLocBySid(PaneRecord.sid);
- if (paneLoc != -1)
- records.remove(paneLoc);
-
+ int paneLoc = findFirstRecordLocBySid(PaneRecord.sid);
+ if (paneLoc != -1)
+ records.remove(paneLoc);
+
int loc = findFirstRecordLocBySid(WindowTwoRecord.sid);
PaneRecord r = new PaneRecord();
r.setX((short)xSplitPos);
sel.setPane(PANE_LOWER_RIGHT);
}
-
+
/**
* Returns the information regarding the currently configured pane (split or freeze).
* @return null if no pane configured, or the pane information.
PaneRecord rec = (PaneRecord)findFirstRecordBySid(PaneRecord.sid);
if (rec == null)
return null;
-
+
return new PaneInformation(rec.getX(), rec.getY(), rec.getTopRow(),
- rec.getLeftColumn(), (byte)rec.getActivePane(), windowTwo.getFreezePanes());
+ rec.getLeftColumn(), (byte)rec.getActivePane(), windowTwo.getFreezePanes());
}
public SelectionRecord getSelection()
*/
public ProtectRecord getProtect()
{
- if (protect == null) {
- protect = (ProtectRecord)createProtect();
- //Insert the newlycreated protect record at the end of the record (just before the EOF)
- int loc = findFirstRecordLocBySid(EOFRecord.sid);
- records.add(loc, protect);
- }
+ if (protect == null) {
+ protect = (ProtectRecord)createProtect();
+ //Insert the newlycreated protect record at the end of the record (just before the EOF)
+ int loc = findFirstRecordLocBySid(EOFRecord.sid);
+ records.add(loc, protect);
+ }
return protect;
}
*/
public PasswordRecord getPassword()
{
- if (password == null) {
- password = createPassword();
- //Insert the newly created password record at the end of the record (just before the EOF)
- int loc = findFirstRecordLocBySid(EOFRecord.sid);
- records.add(loc, password);
- }
+ if (password == null) {
+ password = createPassword();
+ //Insert the newly created password record at the end of the record (just before the EOF)
+ int loc = findFirstRecordLocBySid(EOFRecord.sid);
+ records.add(loc, password);
+ }
return password;
}
* @return whether gridlines are displayed
*/
public boolean isDisplayGridlines() {
- return windowTwo.getDisplayGridlines();
+ return windowTwo.getDisplayGridlines();
}
/**
* @return whether formulas are displayed
*/
public boolean isDisplayFormulas() {
- return windowTwo.getDisplayFormulas();
+ return windowTwo.getDisplayFormulas();
}
/**
* @return whether RowColHeadings are displayed
*/
public boolean isDisplayRowColHeadings() {
- return windowTwo.getDisplayRowColHeadings();
+ return windowTwo.getDisplayRowColHeadings();
}
-
+
/**
- * @return whether an uncalced record must be inserted or not at generation
- */
- public boolean getUncalced() {
- return uncalced;
- }
- /**
- * @param uncalced whether an uncalced record must be inserted or not at generation
- */
- public void setUncalced(boolean uncalced) {
- this.uncalced = uncalced;
- }
+ * @return whether an uncalced record must be inserted or not at generation
+ */
+ public boolean getUncalced() {
+ return uncalced;
+ }
+ /**
+ * @param uncalced whether an uncalced record must be inserted or not at generation
+ */
+ public void setUncalced(boolean uncalced) {
+ this.uncalced = uncalced;
+ }
- /**
+ /**
* Returns the array of margins. If not created, will create.
*
* @return the array of marings.
protected Margin[] getMargins() {
if (margins == null)
margins = new Margin[4];
- return margins;
+ return margins;
}
/**
boolean noDrawingRecordsFound = (loc == -1);
if (noDrawingRecordsFound)
{
- if(!createIfMissing) {
- // None found, and not allowed to add in
- return -1;
- }
-
+ if(!createIfMissing) {
+ // None found, and not allowed to add in
+ return -1;
+ }
+
EscherAggregate aggregate = new EscherAggregate( drawingManager );
loc = findFirstRecordLocBySid(EscherAggregate.sid);
if (loc == -1)
* @param breaks The page record to be shifted
* @param start Starting "main" value to shift breaks
* @param stop Ending "main" value to shift breaks
- * @param count number of units (rows/columns) to shift by
+ * @param count number of units (rows/columns) to shift by
*/
public void shiftBreaks(PageBreakRecord breaks, short start, short stop, int count) {
-
- if(rowBreaks == null)
- return;
- Iterator iterator = breaks.getBreaksIterator();
- List shiftedBreak = new ArrayList();
- while(iterator.hasNext())
- {
- PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
- short breakLocation = breakItem.main;
- boolean inStart = (breakLocation >= start);
- boolean inEnd = (breakLocation <= stop);
- if(inStart && inEnd)
- shiftedBreak.add(breakItem);
- }
-
- iterator = shiftedBreak.iterator();
- while (iterator.hasNext()) {
- PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
- breaks.removeBreak(breakItem.main);
- breaks.addBreak((short)(breakItem.main+count), breakItem.subFrom, breakItem.subTo);
- }
- }
-
+
+ if(rowBreaks == null)
+ return;
+ Iterator iterator = breaks.getBreaksIterator();
+ List shiftedBreak = new ArrayList();
+ while(iterator.hasNext())
+ {
+ PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
+ short breakLocation = breakItem.main;
+ boolean inStart = (breakLocation >= start);
+ boolean inEnd = (breakLocation <= stop);
+ if(inStart && inEnd)
+ shiftedBreak.add(breakItem);
+ }
+
+ iterator = shiftedBreak.iterator();
+ while (iterator.hasNext()) {
+ PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
+ breaks.removeBreak(breakItem.main);
+ breaks.addBreak((short)(breakItem.main+count), breakItem.subFrom, breakItem.subTo);
+ }
+ }
+
/**
* Sets a page break at the indicated row
* @param row
*/
- public void setRowBreak(int row, short fromCol, short toCol) {
- if (rowBreaks == null) {
+ public void setRowBreak(int row, short fromCol, short toCol) {
+ if (rowBreaks == null) {
int loc = findFirstRecordLocBySid(WindowTwoRecord.sid);
rowBreaks = new PageBreakRecord(PageBreakRecord.HORIZONTAL_SID);
records.add(loc, rowBreaks);
- }
- rowBreaks.addBreak((short)row, fromCol, toCol);
+ }
+ rowBreaks.addBreak((short)row, fromCol, toCol);
}
/**
* @param row
*/
public void removeRowBreak(int row) {
- if (rowBreaks == null)
- throw new IllegalArgumentException("Sheet does not define any row breaks");
- rowBreaks.removeBreak((short)row);
+ if (rowBreaks == null)
+ throw new IllegalArgumentException("Sheet does not define any row breaks");
+ rowBreaks.removeBreak((short)row);
}
/**
* @return true if the specified row has a page break
*/
public boolean isRowBroken(int row) {
- return (rowBreaks == null) ? false : rowBreaks.getBreak((short)row) != null;
+ return (rowBreaks == null) ? false : rowBreaks.getBreak((short)row) != null;
}
/**
*
*/
public void setColumnBreak(short column, short fromRow, short toRow) {
- if (colBreaks == null) {
+ if (colBreaks == null) {
int loc = findFirstRecordLocBySid(WindowTwoRecord.sid);
colBreaks = new PageBreakRecord(PageBreakRecord.VERTICAL_SID);
records.add(loc, colBreaks);
- }
- colBreaks.addBreak(column, fromRow, toRow);
+ }
+ colBreaks.addBreak(column, fromRow, toRow);
}
/**
*
*/
public void removeColumnBreak(short column) {
- if (colBreaks == null)
- throw new IllegalArgumentException("Sheet does not define any column breaks");
-
- colBreaks.removeBreak(column);
+ if (colBreaks == null)
+ throw new IllegalArgumentException("Sheet does not define any column breaks");
+
+ colBreaks.removeBreak(column);
}
/**
* @return true if the specified column has a page break
*/
public boolean isColumnBroken(short column) {
- return (colBreaks == null) ? false : colBreaks.getBreak(column) != null;
+ return (colBreaks == null) ? false : colBreaks.getBreak(column) != null;
}
-
+
/**
* Shifts the horizontal page breaks for the indicated count
* @param startingRow
* @param count
*/
public void shiftRowBreaks(int startingRow, int endingRow, int count) {
- shiftBreaks(rowBreaks, (short)startingRow, (short)endingRow, (short)count);
+ shiftBreaks(rowBreaks, (short)startingRow, (short)endingRow, (short)count);
}
/**
* @param count
*/
public void shiftColumnBreaks(short startingCol, short endingCol, short count) {
- shiftBreaks(colBreaks, startingCol, endingCol, count);
+ shiftBreaks(colBreaks, startingCol, endingCol, count);
}
-
+
/**
* Returns all the row page breaks
* @return all the row page breaks
*/
public Iterator getRowBreaks() {
- return rowBreaks.getBreaksIterator();
+ return rowBreaks.getBreaksIterator();
}
-
+
/**
* Returns the number of row page breaks
* @return the number of row page breaks
*/
public int getNumRowBreaks(){
- return (rowBreaks == null) ? 0 : (int)rowBreaks.getNumBreaks();
+ return (rowBreaks == null) ? 0 : (int)rowBreaks.getNumBreaks();
}
-
+
/**
* Returns all the column page breaks
* @return all the column page breaks
*/
public Iterator getColumnBreaks(){
- return colBreaks.getBreaksIterator();
+ return colBreaks.getBreaksIterator();
}
-
+
/**
* Returns the number of column page breaks
* @return the number of column page breaks
*/
public int getNumColumnBreaks(){
- return (colBreaks == null) ? 0 : (int)colBreaks.getNumBreaks();
+ return (colBreaks == null) ? 0 : (int)colBreaks.getNumBreaks();
}
public void setColumnGroupCollapsed( short columnNumber, boolean collapsed )
records.add(protIdx+2,srec);
scenprotect = srec;
}
- }
+ }
/**
- * unprotect objects in the sheet (will not protect them, but any set to false are
+ * unprotect objects in the sheet (will not protect them, but any set to false are
* unprotected.
* @param sheet is unprotected (false = unprotect)
* @param objects are unprotected (false = unprotect)
* @param scenarios are unprotected (false = unprotect)
*/
public void unprotectSheet( boolean sheet, boolean objects, boolean scenarios ) {
- int protIdx = -1;
+
if (!sheet) {
ProtectRecord prec = getProtect();
prec.setProtect(sheet);
PasswordRecord pass = getPassword();
pass.setPassword((short)00);
- }
+ }
if(objprotect != null && !objects) {
objprotect.setProtect(false);
}
if(scenprotect != null && !scenarios) {
scenprotect.setProtect(false);
}
- }
+ }
/**
* @return {sheet is protected, objects are proteced, scenarios are protected}
*/
public boolean[] isProtected() {
- return new boolean[] { (protect != null && protect.getProtect()),
+ return new boolean[] { (protect != null && protect.getProtect()),
(objprotect != null && objprotect.getProtect()),
(scenprotect != null && scenprotect.getProtect())};
}
-
-// private void collapseColumn( short columnNumber )
-// {
-// int idx = findColumnIdx( columnNumber, 0 );
-// if (idx == -1)
-// return;
-//
-// // Find the start of the group.
-// ColumnInfoRecord columnInfo = (ColumnInfoRecord) columnSizes.get( findStartOfColumnOutlineGroup( idx ) );
-//
-// // Hide all the columns until the end of the group
-// columnInfo = writeHidden( columnInfo, idx, true );
-//
-// // Write collapse field
-// setColumn( (short) ( columnInfo.getLastColumn() + 1 ), null, null, null, Boolean.TRUE);
-// }
-
-// private void expandColumn( short columnNumber )
-// {
-// int idx = findColumnIdx( columnNumber, 0 );
-// if (idx == -1)
-// return;
-//
-// // If it is already exapanded do nothing.
-// if (!isColumnGroupCollapsed(idx))
-// return;
-//
-// // Find the start of the group.
-// int startIdx = findStartOfColumnOutlineGroup( idx );
-// ColumnInfoRecord columnInfo = getColInfo( startIdx );
-//
-// // Find the end of the group.
-// int endIdx = findEndOfColumnOutlineGroup( idx );
-// ColumnInfoRecord endColumnInfo = getColInfo( endIdx );
-//
-// // expand:
-// // colapsed bit must be unset
-// // hidden bit gets unset _if_ surrounding groups are expanded you can determine
-// // this by looking at the hidden bit of the enclosing group. You will have
-// // to look at the start and the end of the current group to determine which
-// // is the enclosing group
-// // hidden bit only is altered for this outline level. ie. don't uncollapse contained groups
-// if (!isColumnGroupHiddenByParent( idx ))
-// {
-// for (int i = startIdx; i <= endIdx; i++)
-// {
-// if (columnInfo.getOutlineLevel() == getColInfo(i).getOutlineLevel())
-// getColInfo(i).setHidden( false );
-// }
-// }
-//
-// // Write collapse field
-// setColumn( (short) ( columnInfo.getLastColumn() + 1 ), null, null, null, Boolean.FALSE);
-// }
-
-// private boolean isColumnGroupCollapsed( int idx )
-// {
-// int endOfOutlineGroupIdx = findEndOfColumnOutlineGroup( idx );
-// if (endOfOutlineGroupIdx >= columnSizes.size())
-// return false;
-// if (getColInfo(endOfOutlineGroupIdx).getLastColumn() + 1 != getColInfo(endOfOutlineGroupIdx + 1).getFirstColumn())
-// return false;
-// else
-// return getColInfo(endOfOutlineGroupIdx+1).getCollapsed();
-// }
-
-// private boolean isColumnGroupHiddenByParent( int idx )
-// {
-// // Look out outline details of end
-// int endLevel;
-// boolean endHidden;
-// int endOfOutlineGroupIdx = findEndOfColumnOutlineGroup( idx );
-// if (endOfOutlineGroupIdx >= columnSizes.size())
-// {
-// endLevel = 0;
-// endHidden = false;
-// }
-// else if (getColInfo(endOfOutlineGroupIdx).getLastColumn() + 1 != getColInfo(endOfOutlineGroupIdx + 1).getFirstColumn())
-// {
-// endLevel = 0;
-// endHidden = false;
-// }
-// else
-// {
-// endLevel = getColInfo( endOfOutlineGroupIdx + 1).getOutlineLevel();
-// endHidden = getColInfo( endOfOutlineGroupIdx + 1).getHidden();
-// }
-//
-// // Look out outline details of start
-// int startLevel;
-// boolean startHidden;
-// int startOfOutlineGroupIdx = findStartOfColumnOutlineGroup( idx );
-// if (startOfOutlineGroupIdx <= 0)
-// {
-// startLevel = 0;
-// startHidden = false;
-// }
-// else if (getColInfo(startOfOutlineGroupIdx).getFirstColumn() - 1 != getColInfo(startOfOutlineGroupIdx - 1).getLastColumn())
-// {
-// startLevel = 0;
-// startHidden = false;
-// }
-// else
-// {
-// startLevel = getColInfo( startOfOutlineGroupIdx - 1).getOutlineLevel();
-// startHidden = getColInfo( startOfOutlineGroupIdx - 1 ).getHidden();
-// }
-//
-// if (endLevel > startLevel)
-// {
-// return endHidden;
-// }
-// else
-// {
-// return startHidden;
-// }
-// }
-
-// private ColumnInfoRecord getColInfo(int idx)
-// {
-// return columns.getColInfo( idx );
-// }
-
-// private int findStartOfColumnOutlineGroup(int idx)
-// {
-// // Find the start of the group.
-// ColumnInfoRecord columnInfo = (ColumnInfoRecord) columnSizes.get( idx );
-// int level = columnInfo.getOutlineLevel();
-// while (idx != 0)
-// {
-// ColumnInfoRecord prevColumnInfo = (ColumnInfoRecord) columnSizes.get( idx - 1 );
-// if (columnInfo.getFirstColumn() - 1 == prevColumnInfo.getLastColumn())
-// {
-// if (prevColumnInfo.getOutlineLevel() < level)
-// {
-// break;
-// }
-// idx--;
-// columnInfo = prevColumnInfo;
-// }
-// else
-// {
-// break;
-// }
-// }
-//
-// return idx;
-// }
-
-// private int findEndOfColumnOutlineGroup(int idx)
-// {
-// // Find the end of the group.
-// ColumnInfoRecord columnInfo = (ColumnInfoRecord) columnSizes.get( idx );
-// int level = columnInfo.getOutlineLevel();
-// while (idx < columnSizes.size() - 1)
-// {
-// ColumnInfoRecord nextColumnInfo = (ColumnInfoRecord) columnSizes.get( idx + 1 );
-// if (columnInfo.getLastColumn() + 1 == nextColumnInfo.getFirstColumn())
-// {
-// if (nextColumnInfo.getOutlineLevel() < level)
-// {
-// break;
-// }
-// idx++;
-// columnInfo = nextColumnInfo;
-// }
-// else
-// {
-// break;
-// }
-// }
-//
-// return idx;
-// }
+
public void groupRowRange(int fromRow, int toRow, boolean indent)
{
// Grab the guts record, adding if needed
GutsRecord guts = (GutsRecord) findFirstRecordBySid( GutsRecord.sid );
if(guts == null) {
- guts = new GutsRecord();
- records.add(guts);
+ guts = new GutsRecord();
+ records.add(guts);
}
// Set the levels onto it
guts.setRowLevelMax( (short) ( maxLevel + 1 ) );
rows.expandRow( row );
}
}
-
-
-// private void collapseRow( int rowNumber )
-// {
-//
-// // Find the start of the group.
-// int startRow = rows.findStartOfRowOutlineGroup( rowNumber );
-// RowRecord rowRecord = (RowRecord) rows.getRow( startRow );
-//
-// // Hide all the columns until the end of the group
-// int lastRow = rows.writeHidden( rowRecord, startRow, true );
-//
-// // Write collapse field
-// if (getRow(lastRow + 1) != null)
-// {
-// getRow(lastRow + 1).setColapsed( true );
-// }
-// else
-// {
-// RowRecord row = createRow( lastRow + 1);
-// row.setColapsed( true );
-// rows.insertRow( row );
-// }
-// }
-
-// private int findStartOfRowOutlineGroup(int row)
-// {
-// // Find the start of the group.
-// RowRecord rowRecord = rows.getRow( row );
-// int level = rowRecord.getOutlineLevel();
-// int currentRow = row;
-// while (rows.getRow( currentRow ) != null)
-// {
-// rowRecord = rows.getRow( currentRow );
-// if (rowRecord.getOutlineLevel() < level)
-// return currentRow + 1;
-// currentRow--;
-// }
-//
-// return currentRow + 1;
-// }
-
-// private int writeHidden( RowRecord rowRecord, int row, boolean hidden )
-// {
-// int level = rowRecord.getOutlineLevel();
-// while (rowRecord != null && rows.getRow(row).getOutlineLevel() >= level)
-// {
-// rowRecord.setZeroHeight( hidden );
-// row++;
-// rowRecord = rows.getRow( row );
-// }
-// return row - 1;
-// }
-
-// private int findEndOfRowOutlineGroup( int row )
-// {
-// int level = getRow( row ).getOutlineLevel();
-// int currentRow;
-// for (currentRow = row; currentRow < rows.getLastRowNum(); currentRow++)
-// {
-// if (getRow(currentRow) == null || getRow(currentRow).getOutlineLevel() < level)
-// {
-// break;
-// }
-// }
-//
-// return currentRow-1;
-// }
-
-// private boolean isRowGroupCollapsed( int row )
-// {
-// int collapseRow = rows.findEndOfRowOutlineGroup( row ) + 1;
-//
-// if (getRow(collapseRow) == null)
-// return false;
-// else
-// return getRow( collapseRow ).getColapsed();
-// }
-
-
-// private boolean isRowGroupHiddenByParent( int row )
-// {
-// // Look out outline details of end
-// int endLevel;
-// boolean endHidden;
-// int endOfOutlineGroupIdx = rows.findEndOfRowOutlineGroup( row );
-// if (getRow( endOfOutlineGroupIdx + 1 ) == null)
-// {
-// endLevel = 0;
-// endHidden = false;
-// }
-// else
-// {
-// endLevel = getRow( endOfOutlineGroupIdx + 1).getOutlineLevel();
-// endHidden = getRow( endOfOutlineGroupIdx + 1).getZeroHeight();
-// }
-//
-// // Look out outline details of start
-// int startLevel;
-// boolean startHidden;
-// int startOfOutlineGroupIdx = rows.findStartOfRowOutlineGroup( row );
-// if (startOfOutlineGroupIdx - 1 < 0 || getRow(startOfOutlineGroupIdx - 1) == null)
-// {
-// startLevel = 0;
-// startHidden = false;
-// }
-// else
-// {
-// startLevel = getRow( startOfOutlineGroupIdx - 1).getOutlineLevel();
-// startHidden = getRow( startOfOutlineGroupIdx - 1 ).getZeroHeight();
-// }
-//
-// if (endLevel > startLevel)
-// {
-// return endHidden;
-// }
-// else
-// {
-// return startHidden;
-// }
-// }
-
}
-
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
-
package org.apache.poi.hssf.model;
*
* @author Glen Stampoultzis (glens at apache.org)
*/
-public class TestSheet extends TestCase
-{
+public final class TestSheet extends TestCase {
public void testCreateSheet() throws Exception
{
// Check we're adding row and cell aggregates
if ((regionsToAdd % 1027) != 0)
recordsExpected++;
assertTrue("The " + regionsToAdd + " merged regions should have been spread out over " + recordsExpected + " records, not " + recordsAdded, recordsAdded == recordsExpected);
+ // Check we can't add one with invalid date
+ try {
+ sheet.addMergedRegion(10, (short)10, 9, (short)12);
+ fail("Expected an exception to occur");
+ } catch(IllegalArgumentException e) {
+ // occurs during successful test
+ assertEquals("The 'to' row (9) must not be less than the 'from' row (10)", e.getMessage());
+ }
+ try {
+ sheet.addMergedRegion(10, (short)10, 12, (short)9);
+ fail("Expected an exception to occur");
+ } catch(IllegalArgumentException e) {
+ // occurs during successful test
+ assertEquals("The 'to' col (9) must not be less than the 'from' col (10)", e.getMessage());
+ }
}
public void testRemoveMergedRegion()
MergeCellsRecord merged = new MergeCellsRecord();
merged.addArea(0, (short)0, 1, (short)2);
- records.add(new RowRecord());
- records.add(new RowRecord());
- records.add(new RowRecord());
+ records.add(new RowRecord(0));
+ records.add(new RowRecord(1));
+ records.add(new RowRecord(2));
records.add(merged);
Sheet sheet = Sheet.createSheet(records, 0);
*/
public void testRowAggregation() {
List records = new ArrayList();
- RowRecord row = new RowRecord();
- row.setRowNumber(0);
- records.add(row);
-
- row = new RowRecord();
- row.setRowNumber(1);
- records.add(row);
+ records.add(new RowRecord(0));
+ records.add(new RowRecord(1));
records.add(new StringRecord());
-
- row = new RowRecord();
- row.setRowNumber(2);
- records.add(row);
-
+ records.add(new RowRecord(2));
Sheet sheet = Sheet.createSheet(records, 0);
assertNotNull("Row [2] was skipped", sheet.getRow(2));
Iterator iterator = sheet.getRowBreaks();
while (iterator.hasNext()) {
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
- int main = (int)breakItem.main;
+ int main = breakItem.main;
if (main != 0 && main != 10 && main != 11) fail("Invalid page break");
- if (main == 0) is0 = true;
+ if (main == 0) is0 = true;
if (main == 10) is10= true;
if (main == 11) is11 = true;
}
assertFalse("row should be removed", sheet.isRowBroken(10));
assertEquals("no more breaks", 0, sheet.getNumRowBreaks());
-
-
}
/**
Iterator iterator = sheet.getColumnBreaks();
while (iterator.hasNext()) {
PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
- int main = (int)breakItem.main;
+ int main = breakItem.main;
if (main != 0 && main != 1 && main != 10 && main != 15) fail("Invalid page break");
- if (main == 0) is0 = true;
- if (main == 1) is1 = true;
+ if (main == 0) is0 = true;
+ if (main == 1) is1 = true;
if (main == 10) is10= true;
if (main == 15) is15 = true;
}
* works as designed.
*/
public void testXFIndexForColumn() {
- try{
- final short TEST_IDX = 10;
- final short DEFAULT_IDX = 0xF; // 15
- short xfindex = Short.MIN_VALUE;
- Sheet sheet = Sheet.createSheet();
-
- // without ColumnInfoRecord
- xfindex = sheet.getXFIndexForColAt((short) 0);
- assertEquals(DEFAULT_IDX, xfindex);
- xfindex = sheet.getXFIndexForColAt((short) 1);
- assertEquals(DEFAULT_IDX, xfindex);
-
- ColumnInfoRecord nci = ( ColumnInfoRecord ) sheet.createColInfo();
- sheet.columns.insertColumn(nci);
-
- // single column ColumnInfoRecord
- nci.setFirstColumn((short) 2);
- nci.setLastColumn((short) 2);
- nci.setXFIndex(TEST_IDX);
- xfindex = sheet.getXFIndexForColAt((short) 0);
- assertEquals(DEFAULT_IDX, xfindex);
- xfindex = sheet.getXFIndexForColAt((short) 1);
- assertEquals(DEFAULT_IDX, xfindex);
- xfindex = sheet.getXFIndexForColAt((short) 2);
- assertEquals(TEST_IDX, xfindex);
- xfindex = sheet.getXFIndexForColAt((short) 3);
- assertEquals(DEFAULT_IDX, xfindex);
-
- // ten column ColumnInfoRecord
- nci.setFirstColumn((short) 2);
- nci.setLastColumn((short) 11);
- nci.setXFIndex(TEST_IDX);
- xfindex = sheet.getXFIndexForColAt((short) 1);
- assertEquals(DEFAULT_IDX, xfindex);
- xfindex = sheet.getXFIndexForColAt((short) 2);
- assertEquals(TEST_IDX, xfindex);
- xfindex = sheet.getXFIndexForColAt((short) 6);
- assertEquals(TEST_IDX, xfindex);
- xfindex = sheet.getXFIndexForColAt((short) 11);
- assertEquals(TEST_IDX, xfindex);
- xfindex = sheet.getXFIndexForColAt((short) 12);
- assertEquals(DEFAULT_IDX, xfindex);
-
- // single column ColumnInfoRecord starting at index 0
- nci.setFirstColumn((short) 0);
- nci.setLastColumn((short) 0);
- nci.setXFIndex(TEST_IDX);
- xfindex = sheet.getXFIndexForColAt((short) 0);
- assertEquals(TEST_IDX, xfindex);
- xfindex = sheet.getXFIndexForColAt((short) 1);
- assertEquals(DEFAULT_IDX, xfindex);
-
- // ten column ColumnInfoRecord starting at index 0
- nci.setFirstColumn((short) 0);
- nci.setLastColumn((short) 9);
- nci.setXFIndex(TEST_IDX);
- xfindex = sheet.getXFIndexForColAt((short) 0);
- assertEquals(TEST_IDX, xfindex);
- xfindex = sheet.getXFIndexForColAt((short) 7);
- assertEquals(TEST_IDX, xfindex);
- xfindex = sheet.getXFIndexForColAt((short) 9);
- assertEquals(TEST_IDX, xfindex);
- xfindex = sheet.getXFIndexForColAt((short) 10);
- assertEquals(DEFAULT_IDX, xfindex);
- }
- catch(Exception e){e.printStackTrace();fail(e.getMessage());}
+ final short TEST_IDX = 10;
+ final short DEFAULT_IDX = 0xF; // 15
+ short xfindex = Short.MIN_VALUE;
+ Sheet sheet = Sheet.createSheet();
+
+ // without ColumnInfoRecord
+ xfindex = sheet.getXFIndexForColAt((short) 0);
+ assertEquals(DEFAULT_IDX, xfindex);
+ xfindex = sheet.getXFIndexForColAt((short) 1);
+ assertEquals(DEFAULT_IDX, xfindex);
+
+ ColumnInfoRecord nci = ( ColumnInfoRecord ) sheet.createColInfo();
+ sheet.columns.insertColumn(nci);
+
+ // single column ColumnInfoRecord
+ nci.setFirstColumn((short) 2);
+ nci.setLastColumn((short) 2);
+ nci.setXFIndex(TEST_IDX);
+ xfindex = sheet.getXFIndexForColAt((short) 0);
+ assertEquals(DEFAULT_IDX, xfindex);
+ xfindex = sheet.getXFIndexForColAt((short) 1);
+ assertEquals(DEFAULT_IDX, xfindex);
+ xfindex = sheet.getXFIndexForColAt((short) 2);
+ assertEquals(TEST_IDX, xfindex);
+ xfindex = sheet.getXFIndexForColAt((short) 3);
+ assertEquals(DEFAULT_IDX, xfindex);
+
+ // ten column ColumnInfoRecord
+ nci.setFirstColumn((short) 2);
+ nci.setLastColumn((short) 11);
+ nci.setXFIndex(TEST_IDX);
+ xfindex = sheet.getXFIndexForColAt((short) 1);
+ assertEquals(DEFAULT_IDX, xfindex);
+ xfindex = sheet.getXFIndexForColAt((short) 2);
+ assertEquals(TEST_IDX, xfindex);
+ xfindex = sheet.getXFIndexForColAt((short) 6);
+ assertEquals(TEST_IDX, xfindex);
+ xfindex = sheet.getXFIndexForColAt((short) 11);
+ assertEquals(TEST_IDX, xfindex);
+ xfindex = sheet.getXFIndexForColAt((short) 12);
+ assertEquals(DEFAULT_IDX, xfindex);
+
+ // single column ColumnInfoRecord starting at index 0
+ nci.setFirstColumn((short) 0);
+ nci.setLastColumn((short) 0);
+ nci.setXFIndex(TEST_IDX);
+ xfindex = sheet.getXFIndexForColAt((short) 0);
+ assertEquals(TEST_IDX, xfindex);
+ xfindex = sheet.getXFIndexForColAt((short) 1);
+ assertEquals(DEFAULT_IDX, xfindex);
+
+ // ten column ColumnInfoRecord starting at index 0
+ nci.setFirstColumn((short) 0);
+ nci.setLastColumn((short) 9);
+ nci.setXFIndex(TEST_IDX);
+ xfindex = sheet.getXFIndexForColAt((short) 0);
+ assertEquals(TEST_IDX, xfindex);
+ xfindex = sheet.getXFIndexForColAt((short) 7);
+ assertEquals(TEST_IDX, xfindex);
+ xfindex = sheet.getXFIndexForColAt((short) 9);
+ assertEquals(TEST_IDX, xfindex);
+ xfindex = sheet.getXFIndexForColAt((short) 10);
+ assertEquals(DEFAULT_IDX, xfindex);
}
-
}
+
import java.lang.reflect.Field;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import junit.framework.TestCase;
import org.apache.poi.hssf.record.ColumnInfoRecord;
-import org.apache.poi.hssf.record.MergeCellsRecord;
-import org.apache.poi.hssf.record.PageBreakRecord;
-import org.apache.poi.hssf.record.RowRecord;
-import org.apache.poi.hssf.record.StringRecord;
/**
* @author Tony Poppleton
*/
-public class TestSheetAdditional extends TestCase
-{
- /**
- * Constructor for SheetTest.
- * @param arg0
- */
- public TestSheetAdditional(String arg0)
- {
- super(arg0);
- }
+public final class TestSheetAdditional extends TestCase {
- public void testAddMergedRegion()
- {
- Sheet sheet = Sheet.createSheet();
- int regionsToAdd = 4096;
- int startRecords = sheet.getRecords().size();
-
- //simple test that adds a load of regions
- for (int n = 0; n < regionsToAdd; n++)
- {
- int index = sheet.addMergedRegion(0, (short) 0, 1, (short) 1);
- assertTrue("Merged region index expected to be " + n + " got " + index, index == n);
- }
-
- //test all the regions were indeed added
- assertTrue(sheet.getNumMergedRegions() == regionsToAdd);
-
- //test that the regions were spread out over the appropriate number of records
- int recordsAdded = sheet.getRecords().size() - startRecords;
- int recordsExpected = regionsToAdd/1027;
- if ((regionsToAdd % 1027) != 0)
- recordsExpected++;
- assertTrue("The " + regionsToAdd + " merged regions should have been spread out over " + recordsExpected + " records, not " + recordsAdded, recordsAdded == recordsExpected);
-
- // Check we can't add one with invalud date
- try {
- sheet.addMergedRegion(10, (short)10, 9, (short)12);
- fail();
- } catch(IllegalArgumentException e) {}
- try {
- sheet.addMergedRegion(10, (short)10, 12, (short)9);
- fail();
- } catch(IllegalArgumentException e) {}
- }
-
- public void testRemoveMergedRegion()
- {
- Sheet sheet = Sheet.createSheet();
- int regionsToAdd = 4096;
-
- for (int n = 0; n < regionsToAdd; n++)
- sheet.addMergedRegion(0, (short) 0, 1, (short) 1);
-
- int records = sheet.getRecords().size();
-
- //remove a third from the beginning
- for (int n = 0; n < regionsToAdd/3; n++)
- {
- sheet.removeMergedRegion(0);
- //assert they have been deleted
- assertTrue("Num of regions should be " + (regionsToAdd - n - 1) + " not " + sheet.getNumMergedRegions(), sheet.getNumMergedRegions() == regionsToAdd - n - 1);
- }
-
- //assert any record removing was done
- int recordsRemoved = (regionsToAdd/3)/1027; //doesn't work for particular values of regionsToAdd
- assertTrue("Expected " + recordsRemoved + " record to be removed from the starting " + records + ". Currently there are " + sheet.getRecords().size() + " records", records - sheet.getRecords().size() == recordsRemoved);
- }
-
- /**
- * Bug: 22922 (Reported by Xuemin Guan)
- * <p>
- * Remove mergedregion fails when a sheet loses records after an initial CreateSheet
- * fills up the records.
- *
- */
- public void testMovingMergedRegion() {
- List records = new ArrayList();
-
- MergeCellsRecord merged = new MergeCellsRecord();
- merged.addArea(0, (short)0, 1, (short)2);
- records.add(new RowRecord());
- records.add(new RowRecord());
- records.add(new RowRecord());
- records.add(merged);
-
- Sheet sheet = Sheet.createSheet(records, 0);
- sheet.records.remove(0);
-
- //stub object to throw off list INDEX operations
- sheet.removeMergedRegion(0);
- assertEquals("Should be no more merged regions", 0, sheet.getNumMergedRegions());
- }
-
- public void testGetMergedRegionAt()
- {
- //TODO
- }
-
- public void testGetNumMergedRegions()
- {
- //TODO
- }
-
- public void DISBALEDtestGetCellWidth() throws Exception
- {
+ public void testGetCellWidth() {
Sheet sheet = Sheet.createSheet();
ColumnInfoRecord nci = ( ColumnInfoRecord ) sheet.createColInfo();
nci.setLastColumn((short)10);
nci.setColumnWidth((short)100);
- Field f = null;
- f = Sheet.class.getDeclaredField("columnSizes");
- f.setAccessible(true);
- List columnSizes = new ArrayList();
- f.set(sheet,columnSizes);
- columnSizes.add(nci);
- sheet.records.add(1 + sheet.dimsloc, nci);
- sheet.dimsloc++;
+
+ sheet.columns.insertColumn(nci);
assertEquals((short)100,sheet.getColumnWidth((short)5));
assertEquals((short)100,sheet.getColumnWidth((short)6));
assertEquals((short)100,sheet.getColumnWidth((short)10));
}
- /**
- * Makes sure all rows registered for this sheet are aggregated, they were being skipped
- *
- */
- public void testRowAggregation() {
- List records = new ArrayList();
- RowRecord row = new RowRecord();
- row.setRowNumber(0);
- records.add(row);
-
- row = new RowRecord();
- row.setRowNumber(1);
- records.add(row);
-
- records.add(new StringRecord());
-
- row = new RowRecord();
- row.setRowNumber(2);
- records.add(row);
-
-
- Sheet sheet = Sheet.createSheet(records, 0);
- assertNotNull("Row [2] was skipped", sheet.getRow(2));
-
- }
-
- /**
- * Make sure page break functionality works (in memory)
- *
- */
- public void testRowPageBreaks(){
- short colFrom = 0;
- short colTo = 255;
-
- Sheet sheet = Sheet.createSheet();
- sheet.setRowBreak(0, colFrom, colTo);
-
- assertTrue("no row break at 0", sheet.isRowBroken(0));
- assertEquals("1 row break available", 1, sheet.getNumRowBreaks());
-
- sheet.setRowBreak(0, colFrom, colTo);
- sheet.setRowBreak(0, colFrom, colTo);
-
- assertTrue("no row break at 0", sheet.isRowBroken(0));
- assertEquals("1 row break available", 1, sheet.getNumRowBreaks());
-
- sheet.setRowBreak(10, colFrom, colTo);
- sheet.setRowBreak(11, colFrom, colTo);
-
- assertTrue("no row break at 10", sheet.isRowBroken(10));
- assertTrue("no row break at 11", sheet.isRowBroken(11));
- assertEquals("3 row break available", 3, sheet.getNumRowBreaks());
-
-
- boolean is10 = false;
- boolean is0 = false;
- boolean is11 = false;
-
- Iterator iterator = sheet.getRowBreaks();
- while (iterator.hasNext()) {
- PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
- int main = (int)breakItem.main;
- if (main != 0 && main != 10 && main != 11) fail("Invalid page break");
- if (main == 0) is0 = true;
- if (main == 10) is10= true;
- if (main == 11) is11 = true;
- }
-
- assertTrue("one of the breaks didnt make it", is0 && is10 && is11);
-
- sheet.removeRowBreak(11);
- assertFalse("row should be removed", sheet.isRowBroken(11));
-
- sheet.removeRowBreak(0);
- assertFalse("row should be removed", sheet.isRowBroken(0));
-
- sheet.removeRowBreak(10);
- assertFalse("row should be removed", sheet.isRowBroken(10));
-
- assertEquals("no more breaks", 0, sheet.getNumRowBreaks());
-
-
- }
-
- /**
- * Make sure column pag breaks works properly (in-memory)
- *
- */
- public void testColPageBreaks(){
- short rowFrom = 0;
- short rowTo = (short)65535;
-
- Sheet sheet = Sheet.createSheet();
- sheet.setColumnBreak((short)0, rowFrom, rowTo);
-
- assertTrue("no col break at 0", sheet.isColumnBroken((short)0));
- assertEquals("1 col break available", 1, sheet.getNumColumnBreaks());
-
- sheet.setColumnBreak((short)0, rowFrom, rowTo);
-
- assertTrue("no col break at 0", sheet.isColumnBroken((short)0));
- assertEquals("1 col break available", 1, sheet.getNumColumnBreaks());
-
- sheet.setColumnBreak((short)1, rowFrom, rowTo);
- sheet.setColumnBreak((short)10, rowFrom, rowTo);
- sheet.setColumnBreak((short)15, rowFrom, rowTo);
-
- assertTrue("no col break at 1", sheet.isColumnBroken((short)1));
- assertTrue("no col break at 10", sheet.isColumnBroken((short)10));
- assertTrue("no col break at 15", sheet.isColumnBroken((short)15));
- assertEquals("4 col break available", 4, sheet.getNumColumnBreaks());
-
- boolean is10 = false;
- boolean is0 = false;
- boolean is1 = false;
- boolean is15 = false;
-
- Iterator iterator = sheet.getColumnBreaks();
- while (iterator.hasNext()) {
- PageBreakRecord.Break breakItem = (PageBreakRecord.Break)iterator.next();
- int main = (int)breakItem.main;
- if (main != 0 && main != 1 && main != 10 && main != 15) fail("Invalid page break");
- if (main == 0) is0 = true;
- if (main == 1) is1 = true;
- if (main == 10) is10= true;
- if (main == 15) is15 = true;
- }
-
- assertTrue("one of the breaks didnt make it", is0 && is1 && is10 && is15);
-
- sheet.removeColumnBreak((short)15);
- assertFalse("column break should not be there", sheet.isColumnBroken((short)15));
-
- sheet.removeColumnBreak((short)0);
- assertFalse("column break should not be there", sheet.isColumnBroken((short)0));
-
- sheet.removeColumnBreak((short)1);
- assertFalse("column break should not be there", sheet.isColumnBroken((short)1));
-
- sheet.removeColumnBreak((short)10);
- assertFalse("column break should not be there", sheet.isColumnBroken((short)10));
-
- assertEquals("no more breaks", 0, sheet.getNumColumnBreaks());
- }
-
}