Merged revisions 700005,700203-700204 via svnmerge from

https://svn.apache.org/repos/asf/poi/trunk

........
  r700005 | josh | 2008-09-29 00:27:14 -0700 (Mon, 29 Sep 2008) | 1 line
  
  Fix for bug 45890 - made HSSFSheet.shiftRows also update conditional formats
........
  r700203 | josh | 2008-09-29 11:43:53 -0700 (Mon, 29 Sep 2008) | 1 line
  
  Refactoring row-blocks record reading logic in Sheet
........
  r700204 | josh | 2008-09-29 11:48:43 -0700 (Mon, 29 Sep 2008) | 1 line
  
  Should have been submitted with c700203 (Refactoring row-blocks record reading logic in Sheet)
........


git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@700243 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-09-29 20:38:55 +00:00
parent 96cb7321ba
commit fad1570e1f
30 changed files with 523 additions and 733 deletions

View File

@ -67,6 +67,7 @@
<action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action> <action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
</release> </release>
<release version="3.2-alpha1" date="2008-??-??"> <release version="3.2-alpha1" date="2008-??-??">
<action dev="POI-DEVELOPERS" type="add">45890 - fixed HSSFSheet.shiftRows to also update conditional formats</action>
<action dev="POI-DEVELOPERS" type="add">45865 modified Formula Parser/Evaluator to handle cross-worksheet formulas</action> <action dev="POI-DEVELOPERS" type="add">45865 modified Formula Parser/Evaluator to handle cross-worksheet formulas</action>
<action dev="POI-DEVELOPERS" type="add">Optimised the FormulaEvaluator to take cell dependencies into account</action> <action dev="POI-DEVELOPERS" type="add">Optimised the FormulaEvaluator to take cell dependencies into account</action>
<action dev="POI-DEVELOPERS" type="add">16936 - Initial support for whole-row cell styling</action> <action dev="POI-DEVELOPERS" type="add">16936 - Initial support for whole-row cell styling</action>

View File

@ -64,6 +64,7 @@
<action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action> <action dev="POI-DEVELOPERS" type="add">Created a common interface for handling Excel files, irrespective of if they are .xls or .xlsx</action>
</release> </release>
<release version="3.2-alpha1" date="2008-??-??"> <release version="3.2-alpha1" date="2008-??-??">
<action dev="POI-DEVELOPERS" type="add">45890 - fixed HSSFSheet.shiftRows to also update conditional formats</action>
<action dev="POI-DEVELOPERS" type="add">45865 modified Formula Parser/Evaluator to handle cross-worksheet formulas</action> <action dev="POI-DEVELOPERS" type="add">45865 modified Formula Parser/Evaluator to handle cross-worksheet formulas</action>
<action dev="POI-DEVELOPERS" type="add">Optimised the FormulaEvaluator to take cell dependencies into account</action> <action dev="POI-DEVELOPERS" type="add">Optimised the FormulaEvaluator to take cell dependencies into account</action>
<action dev="POI-DEVELOPERS" type="add">16936 - Initial support for whole-row cell styling</action> <action dev="POI-DEVELOPERS" type="add">16936 - Initial support for whole-row cell styling</action>

View File

@ -83,7 +83,7 @@ public class ModelFactory implements ERFListener
currentmodel = new Workbook(); currentmodel = new Workbook();
break; break;
case BOFRecord.TYPE_WORKSHEET: case BOFRecord.TYPE_WORKSHEET:
currentmodel = new Sheet(); currentmodel = Sheet.createSheet();
break; break;
default: default:
throw new RuntimeException("Unsupported model type "+bof.getType()); throw new RuntimeException("Unsupported model type "+bof.getType());

View File

@ -19,7 +19,10 @@ package org.apache.poi.hssf.model;
import java.util.List; import java.util.List;
import org.apache.poi.hssf.record.ArrayRecord;
import org.apache.poi.hssf.record.BOFRecord; import org.apache.poi.hssf.record.BOFRecord;
import org.apache.poi.hssf.record.BlankRecord;
import org.apache.poi.hssf.record.BoolErrRecord;
import org.apache.poi.hssf.record.CalcCountRecord; import org.apache.poi.hssf.record.CalcCountRecord;
import org.apache.poi.hssf.record.CalcModeRecord; import org.apache.poi.hssf.record.CalcModeRecord;
import org.apache.poi.hssf.record.DVALRecord; import org.apache.poi.hssf.record.DVALRecord;
@ -30,22 +33,30 @@ import org.apache.poi.hssf.record.DimensionsRecord;
import org.apache.poi.hssf.record.DrawingRecord; import org.apache.poi.hssf.record.DrawingRecord;
import org.apache.poi.hssf.record.DrawingSelectionRecord; import org.apache.poi.hssf.record.DrawingSelectionRecord;
import org.apache.poi.hssf.record.EOFRecord; import org.apache.poi.hssf.record.EOFRecord;
import org.apache.poi.hssf.record.FormulaRecord;
import org.apache.poi.hssf.record.GridsetRecord; import org.apache.poi.hssf.record.GridsetRecord;
import org.apache.poi.hssf.record.GutsRecord; import org.apache.poi.hssf.record.GutsRecord;
import org.apache.poi.hssf.record.HyperlinkRecord; import org.apache.poi.hssf.record.HyperlinkRecord;
import org.apache.poi.hssf.record.IndexRecord; import org.apache.poi.hssf.record.IndexRecord;
import org.apache.poi.hssf.record.IterationRecord; import org.apache.poi.hssf.record.IterationRecord;
import org.apache.poi.hssf.record.LabelRecord;
import org.apache.poi.hssf.record.LabelSSTRecord;
import org.apache.poi.hssf.record.NumberRecord;
import org.apache.poi.hssf.record.ObjRecord; import org.apache.poi.hssf.record.ObjRecord;
import org.apache.poi.hssf.record.PaneRecord; import org.apache.poi.hssf.record.PaneRecord;
import org.apache.poi.hssf.record.PrecisionRecord; import org.apache.poi.hssf.record.PrecisionRecord;
import org.apache.poi.hssf.record.PrintGridlinesRecord; import org.apache.poi.hssf.record.PrintGridlinesRecord;
import org.apache.poi.hssf.record.PrintHeadersRecord; import org.apache.poi.hssf.record.PrintHeadersRecord;
import org.apache.poi.hssf.record.RKRecord;
import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.Record;
import org.apache.poi.hssf.record.RecordBase; import org.apache.poi.hssf.record.RecordBase;
import org.apache.poi.hssf.record.RefModeRecord; import org.apache.poi.hssf.record.RefModeRecord;
import org.apache.poi.hssf.record.RowRecord;
import org.apache.poi.hssf.record.SCLRecord; import org.apache.poi.hssf.record.SCLRecord;
import org.apache.poi.hssf.record.SaveRecalcRecord; import org.apache.poi.hssf.record.SaveRecalcRecord;
import org.apache.poi.hssf.record.SelectionRecord; import org.apache.poi.hssf.record.SelectionRecord;
import org.apache.poi.hssf.record.SharedFormulaRecord;
import org.apache.poi.hssf.record.TableRecord;
import org.apache.poi.hssf.record.TextObjectRecord; import org.apache.poi.hssf.record.TextObjectRecord;
import org.apache.poi.hssf.record.UncalcedRecord; import org.apache.poi.hssf.record.UncalcedRecord;
import org.apache.poi.hssf.record.UnknownRecord; import org.apache.poi.hssf.record.UnknownRecord;
@ -324,7 +335,7 @@ final class RecordOrderer {
* It is assumed that at least one row or cell value record has been found prior to the current * It is assumed that at least one row or cell value record has been found prior to the current
* record * record
*/ */
public static boolean isEndOfRowBlock(short sid) { public static boolean isEndOfRowBlock(int sid) {
switch(sid) { switch(sid) {
case DrawingRecord.sid: case DrawingRecord.sid:
case DrawingSelectionRecord.sid: case DrawingSelectionRecord.sid:
@ -344,4 +355,29 @@ final class RecordOrderer {
} }
return PageSettingsBlock.isComponentRecord(sid); return PageSettingsBlock.isComponentRecord(sid);
} }
/**
* @return <code>true</code> if the specified record id normally appears in the row blocks section
* of the sheet records
*/
public static boolean isRowBlockRecord(int sid) {
switch (sid) {
case RowRecord.sid:
case BlankRecord.sid:
case BoolErrRecord.sid:
case FormulaRecord.sid:
case LabelRecord.sid:
case LabelSSTRecord.sid:
case NumberRecord.sid:
case RKRecord.sid:
case ArrayRecord.sid:
case SharedFormulaRecord.sid:
case TableRecord.sid:
return true;
}
return false;
}
} }

View File

@ -39,30 +39,28 @@ public final class RowBlocksReader {
private final List _plainRecords; private final List _plainRecords;
private final SharedValueManager _sfm; private final SharedValueManager _sfm;
private final MergeCellsRecord[] _mergedCellsRecords; private final MergeCellsRecord[] _mergedCellsRecords;
private final int _totalNumberOfRecords;
/** /**
* Also collects any loose MergeCellRecords and puts them in the supplied * Also collects any loose MergeCellRecords and puts them in the supplied
* mergedCellsTable * mergedCellsTable
*/ */
public RowBlocksReader(List recs, int startIx) { public RowBlocksReader(RecordStream rs) {
List plainRecords = new ArrayList(); List plainRecords = new ArrayList();
List shFrmRecords = new ArrayList(); List shFrmRecords = new ArrayList();
List arrayRecords = new ArrayList(); List arrayRecords = new ArrayList();
List tableRecords = new ArrayList(); List tableRecords = new ArrayList();
List mergeCellRecords = new ArrayList(); List mergeCellRecords = new ArrayList();
int endIx = -1; while(!RecordOrderer.isEndOfRowBlock(rs.peekNextSid())) {
for (int i = startIx; i < recs.size(); i++) { // End of row/cell records for the current sheet
Record rec = (Record) recs.get(i); // Note - It is important that this code does not inadvertently add any sheet
if (RecordOrderer.isEndOfRowBlock(rec.getSid())) { // records from a subsequent sheet. For example, if SharedFormulaRecords
// End of row/cell records for the current sheet // are taken from the wrong sheet, this could cause bug 44449.
// Note - It is important that this code does not inadvertently any sheet if (!rs.hasNext()) {
// records from a subsequent sheet. For example, if SharedFormulaRecords throw new RuntimeException("Failed to find end of row/cell records");
// are taken from the wrong sheet, this could cause bug 44449.
endIx = i;
break;
} }
Record rec = rs.getNext();
List dest; List dest;
switch (rec.getSid()) { switch (rec.getSid()) {
case MergeCellsRecord.sid: dest = mergeCellRecords; break; case MergeCellsRecord.sid: dest = mergeCellRecords; break;
@ -73,9 +71,6 @@ public final class RowBlocksReader {
} }
dest.add(rec); dest.add(rec);
} }
if (endIx < 0) {
throw new RuntimeException("Failed to find end of row/cell records");
}
SharedFormulaRecord[] sharedFormulaRecs = new SharedFormulaRecord[shFrmRecords.size()]; SharedFormulaRecord[] sharedFormulaRecs = new SharedFormulaRecord[shFrmRecords.size()];
ArrayRecord[] arrayRecs = new ArrayRecord[arrayRecords.size()]; ArrayRecord[] arrayRecs = new ArrayRecord[arrayRecords.size()];
TableRecord[] tableRecs = new TableRecord[tableRecords.size()]; TableRecord[] tableRecs = new TableRecord[tableRecords.size()];
@ -87,7 +82,6 @@ public final class RowBlocksReader {
_sfm = SharedValueManager.create(sharedFormulaRecs, arrayRecs, tableRecs); _sfm = SharedValueManager.create(sharedFormulaRecs, arrayRecs, tableRecs);
_mergedCellsRecords = new MergeCellsRecord[mergeCellRecords.size()]; _mergedCellsRecords = new MergeCellsRecord[mergeCellRecords.size()];
mergeCellRecords.toArray(_mergedCellsRecords); mergeCellRecords.toArray(_mergedCellsRecords);
_totalNumberOfRecords = endIx - startIx;
} }
/** /**
@ -99,10 +93,6 @@ public final class RowBlocksReader {
return _mergedCellsRecords; return _mergedCellsRecords;
} }
public int getTotalNumberOfRecords() {
return _totalNumberOfRecords;
}
public SharedValueManager getSharedFormulaManager() { public SharedValueManager getSharedFormulaManager() {
return _sfm; return _sfm;
} }

View File

@ -58,7 +58,6 @@ import org.apache.poi.hssf.record.SelectionRecord;
import org.apache.poi.hssf.record.UncalcedRecord; import org.apache.poi.hssf.record.UncalcedRecord;
import org.apache.poi.hssf.record.WSBoolRecord; import org.apache.poi.hssf.record.WSBoolRecord;
import org.apache.poi.hssf.record.WindowTwoRecord; import org.apache.poi.hssf.record.WindowTwoRecord;
import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
import org.apache.poi.hssf.record.aggregates.ColumnInfoRecordsAggregate; import org.apache.poi.hssf.record.aggregates.ColumnInfoRecordsAggregate;
import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable; import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable;
import org.apache.poi.hssf.record.aggregates.DataValidityTable; import org.apache.poi.hssf.record.aggregates.DataValidityTable;
@ -68,6 +67,7 @@ import org.apache.poi.hssf.record.aggregates.RecordAggregate;
import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate; import org.apache.poi.hssf.record.aggregates.RowRecordsAggregate;
import org.apache.poi.hssf.record.aggregates.RecordAggregate.PositionTrackingVisitor; import org.apache.poi.hssf.record.aggregates.RecordAggregate.PositionTrackingVisitor;
import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor; import org.apache.poi.hssf.record.aggregates.RecordAggregate.RecordVisitor;
import org.apache.poi.hssf.record.formula.FormulaShifter;
import org.apache.poi.hssf.util.CellRangeAddress; import org.apache.poi.hssf.util.CellRangeAddress;
import org.apache.poi.hssf.util.PaneInformation; import org.apache.poi.hssf.util.PaneInformation;
import org.apache.poi.util.POILogFactory; import org.apache.poi.util.POILogFactory;
@ -104,7 +104,6 @@ public final class Sheet implements Model {
private static POILogger log = POILogFactory.getLogger(Sheet.class); private static POILogger log = POILogFactory.getLogger(Sheet.class);
protected ArrayList records = null; protected ArrayList records = null;
protected int dimsloc = -1; // TODO - remove dimsloc
protected PrintGridlinesRecord printGridlines = null; protected PrintGridlinesRecord printGridlines = null;
protected GridsetRecord gridset = null; protected GridsetRecord gridset = null;
private GutsRecord _gutsRecord; private GutsRecord _gutsRecord;
@ -127,11 +126,10 @@ public final class Sheet implements Model {
/** the DimensionsRecord is always present */ /** the DimensionsRecord is always present */
private DimensionsRecord _dimensions; private DimensionsRecord _dimensions;
/** always present */ /** always present */
protected RowRecordsAggregate _rowsAggregate; protected final RowRecordsAggregate _rowsAggregate;
private DataValidityTable _dataValidityTable= null; private DataValidityTable _dataValidityTable= null;
private ConditionalFormattingTable condFormatting; private ConditionalFormattingTable condFormatting;
protected int eofLoc = 0;
private Iterator rowRecIterator = null; private Iterator rowRecIterator = null;
/** Add an UncalcedRecord if not true indicating formulas have not been calculated */ /** Add an UncalcedRecord if not true indicating formulas have not been calculated */
@ -142,14 +140,6 @@ public final class Sheet implements Model {
public static final byte PANE_LOWER_LEFT = (byte)2; public static final byte PANE_LOWER_LEFT = (byte)2;
public static final byte PANE_UPPER_LEFT = (byte)3; public static final byte PANE_UPPER_LEFT = (byte)3;
/**
* Creates new Sheet with no initialization --useless at this point
* @see #createSheet(List,int,int)
*/
public Sheet() {
_mergedCellsTable = new MergedCellsTable();
}
/** /**
* read support (offset used as starting point for search) for low level * read support (offset used as starting point for search) for low level
* API. Pass in an array of Record objects, the sheet number (0 based) and * API. Pass in an array of Record objects, the sheet number (0 based) and
@ -167,178 +157,170 @@ public final class Sheet implements Model {
* @see org.apache.poi.hssf.model.Workbook * @see org.apache.poi.hssf.model.Workbook
* @see org.apache.poi.hssf.record.Record * @see org.apache.poi.hssf.record.Record
*/ */
public static Sheet createSheet(List inRecs, int sheetnum, int offset) public static Sheet createSheet(RecordStream rs) {
{ return new Sheet(rs);
if (log.check( POILogger.DEBUG )) }
log.logFormatted(POILogger.DEBUG, private Sheet(RecordStream rs) {
"Sheet createSheet (existing file) with %", _mergedCellsTable = new MergedCellsTable();
new Integer(inRecs.size())); RowRecordsAggregate rra = null;
Sheet retval = new Sheet();
ArrayList records = new ArrayList(inRecs.size() / 5); records = new ArrayList(128);
// TODO - take chart streams off into separate java objects // TODO - take chart streams off into separate java objects
int bofEofNestingLevel = 0; // nesting level can only get to 2 (when charts are present) int bofEofNestingLevel = 0; // nesting level can only get to 2 (when charts are present)
int dimsloc = -1;
for (int k = offset; k < inRecs.size(); k++) { while (rs.hasNext()) {
Record rec = ( Record ) inRecs.get(k); int recSid = rs.peekNextSid();
if ( rec.getSid() == IndexRecord.sid ) {
// ignore INDEX record because it is only needed by Excel, if ( recSid == CFHeaderRecord.sid ) {
// and POI always re-calculates its contents condFormatting = new ConditionalFormattingTable(rs);
records.add(condFormatting);
continue; continue;
} }
if ( rec.getSid() == CFHeaderRecord.sid ) { if (recSid == ColumnInfoRecord.sid) {
RecordStream rs = new RecordStream(inRecs, k); _columnInfos = new ColumnInfoRecordsAggregate(rs);
retval.condFormatting = new ConditionalFormattingTable(rs); records.add(_columnInfos);
k += rs.getCountRead()-1; continue;
records.add(retval.condFormatting); }
if ( recSid == DVALRecord.sid) {
_dataValidityTable = new DataValidityTable(rs);
records.add(_dataValidityTable);
continue; continue;
} }
if (rec.getSid() == ColumnInfoRecord.sid) { if (RecordOrderer.isRowBlockRecord(recSid) && bofEofNestingLevel == 1 ) {
RecordStream rs = new RecordStream(inRecs, k);
retval._columnInfos = new ColumnInfoRecordsAggregate(rs);
k += rs.getCountRead()-1;
records.add(retval._columnInfos);
continue;
}
if ( rec.getSid() == DVALRecord.sid) {
RecordStream rs = new RecordStream(inRecs, k);
retval._dataValidityTable = new DataValidityTable(rs);
k += rs.getCountRead() - 1; // TODO - convert this method result to be zero based
records.add(retval._dataValidityTable);
continue;
}
// TODO construct RowRecordsAggregate from RecordStream
if ((rec.getSid() == RowRecord.sid || rec.isValue()) && bofEofNestingLevel == 1 ) {
//only add the aggregate once //only add the aggregate once
if (retval._rowsAggregate != null) { if (rra != null) {
throw new RuntimeException("row/cell records found in the wrong place"); throw new RuntimeException("row/cell records found in the wrong place");
} }
RowBlocksReader rbr = new RowBlocksReader(inRecs, k); RowBlocksReader rbr = new RowBlocksReader(rs);
retval._mergedCellsTable.addRecords(rbr.getLooseMergedCells()); _mergedCellsTable.addRecords(rbr.getLooseMergedCells());
retval._rowsAggregate = new RowRecordsAggregate(rbr.getPlainRecordStream(), rbr.getSharedFormulaManager()); rra = new RowRecordsAggregate(rbr.getPlainRecordStream(), rbr.getSharedFormulaManager());
records.add(retval._rowsAggregate); //only add the aggregate once records.add(rra); //only add the aggregate once
k += rbr.getTotalNumberOfRecords() - 1;
continue; continue;
} }
if (PageSettingsBlock.isComponentRecord(rec.getSid())) { if (PageSettingsBlock.isComponentRecord(recSid)) {
RecordStream rs = new RecordStream(inRecs, k);
PageSettingsBlock psb = new PageSettingsBlock(rs); PageSettingsBlock psb = new PageSettingsBlock(rs);
if (bofEofNestingLevel == 1) { if (bofEofNestingLevel == 1) {
if (retval._psBlock == null) { if (_psBlock == null) {
retval._psBlock = psb; _psBlock = psb;
} else { } else {
// more than one 'Page Settings Block' at nesting level 1 ? // more than one 'Page Settings Block' at nesting level 1 ?
// apparently this happens in about 15 test sample files // apparently this happens in about 15 test sample files
} }
} }
records.add(psb); records.add(psb);
k += rs.getCountRead()-1;
continue; continue;
} }
if (rec.getSid() == MergeCellsRecord.sid) { if (recSid == MergeCellsRecord.sid) {
// when the MergedCellsTable is found in the right place, we expect those records to be contiguous // when the MergedCellsTable is found in the right place, we expect those records to be contiguous
RecordStream rs = new RecordStream(inRecs, k); _mergedCellsTable.read(rs);
retval._mergedCellsTable.read(rs);
k += rs.getCountRead()-1;
continue;
}
if (rec.getSid() == UncalcedRecord.sid) {
// don't add UncalcedRecord to the list
retval._isUncalced = true; // this flag is enough
continue; continue;
} }
if (rec.getSid() == BOFRecord.sid) Record rec = rs.getNext();
if ( recSid == IndexRecord.sid ) {
// ignore INDEX record because it is only needed by Excel,
// and POI always re-calculates its contents
continue;
}
if (recSid == UncalcedRecord.sid) {
// don't add UncalcedRecord to the list
_isUncalced = true; // this flag is enough
continue;
}
if (recSid == BOFRecord.sid)
{ {
bofEofNestingLevel++; bofEofNestingLevel++;
if (log.check( POILogger.DEBUG )) if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "Hit BOF record. Nesting increased to " + bofEofNestingLevel); log.log(POILogger.DEBUG, "Hit BOF record. Nesting increased to " + bofEofNestingLevel);
} }
else if (rec.getSid() == EOFRecord.sid) else if (recSid == EOFRecord.sid)
{ {
--bofEofNestingLevel; --bofEofNestingLevel;
if (log.check( POILogger.DEBUG )) if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "Hit EOF record. Nesting decreased to " + bofEofNestingLevel); log.log(POILogger.DEBUG, "Hit EOF record. Nesting decreased to " + bofEofNestingLevel);
if (bofEofNestingLevel == 0) { if (bofEofNestingLevel == 0) {
records.add(rec); records.add(rec);
retval.eofLoc = k;
break; break;
} }
} }
else if (rec.getSid() == DimensionsRecord.sid) else if (recSid == DimensionsRecord.sid)
{ {
// Make a columns aggregate if one hasn't ready been created. // Make a columns aggregate if one hasn't ready been created.
if (retval._columnInfos == null) if (_columnInfos == null)
{ {
retval._columnInfos = new ColumnInfoRecordsAggregate(); _columnInfos = new ColumnInfoRecordsAggregate();
records.add(retval._columnInfos); records.add(_columnInfos);
} }
retval._dimensions = ( DimensionsRecord ) rec; _dimensions = ( DimensionsRecord ) rec;
retval.dimsloc = records.size(); dimsloc = records.size();
} }
else if (rec.getSid() == DefaultColWidthRecord.sid) else if (recSid == DefaultColWidthRecord.sid)
{ {
retval.defaultcolwidth = ( DefaultColWidthRecord ) rec; defaultcolwidth = ( DefaultColWidthRecord ) rec;
} }
else if (rec.getSid() == DefaultRowHeightRecord.sid) else if (recSid == DefaultRowHeightRecord.sid)
{ {
retval.defaultrowheight = ( DefaultRowHeightRecord ) rec; defaultrowheight = ( DefaultRowHeightRecord ) rec;
} }
else if ( rec.getSid() == PrintGridlinesRecord.sid ) else if ( recSid == PrintGridlinesRecord.sid )
{ {
retval.printGridlines = (PrintGridlinesRecord) rec; printGridlines = (PrintGridlinesRecord) rec;
} }
else if ( rec.getSid() == GridsetRecord.sid ) else if ( recSid == GridsetRecord.sid )
{ {
retval.gridset = (GridsetRecord) rec; gridset = (GridsetRecord) rec;
} }
else if ( rec.getSid() == SelectionRecord.sid ) else if ( recSid == SelectionRecord.sid )
{ {
retval.selection = (SelectionRecord) rec; selection = (SelectionRecord) rec;
} }
else if ( rec.getSid() == WindowTwoRecord.sid ) else if ( recSid == WindowTwoRecord.sid )
{ {
retval.windowTwo = (WindowTwoRecord) rec; windowTwo = (WindowTwoRecord) rec;
} }
else if ( rec.getSid() == ProtectRecord.sid ) else if ( recSid == ProtectRecord.sid )
{ {
retval.protect = (ProtectRecord) rec; protect = (ProtectRecord) rec;
} }
else if ( rec.getSid() == ObjectProtectRecord.sid ) else if ( recSid == ObjectProtectRecord.sid )
{ {
retval.objprotect = (ObjectProtectRecord) rec; objprotect = (ObjectProtectRecord) rec;
} }
else if ( rec.getSid() == ScenarioProtectRecord.sid ) else if ( recSid == ScenarioProtectRecord.sid )
{ {
retval.scenprotect = (ScenarioProtectRecord) rec; scenprotect = (ScenarioProtectRecord) rec;
} }
else if ( rec.getSid() == PasswordRecord.sid ) else if ( recSid == PasswordRecord.sid )
{ {
retval.password = (PasswordRecord) rec; password = (PasswordRecord) rec;
} }
records.add(rec); records.add(rec);
} }
if (retval._dimensions == null) { if (_dimensions == null) {
throw new RuntimeException("DimensionsRecord was not found"); throw new RuntimeException("DimensionsRecord was not found");
} }
if (retval.windowTwo == null) { if (windowTwo == null) {
throw new RuntimeException("WINDOW2 was not found"); throw new RuntimeException("WINDOW2 was not found");
} }
if (retval._rowsAggregate == null) { if (rra == null) {
retval._rowsAggregate = new RowRecordsAggregate(); rra = new RowRecordsAggregate();
records.add(retval.dimsloc + 1, retval._rowsAggregate); records.add(dimsloc + 1, rra);
} }
_rowsAggregate = rra;
// put merged cells table in the right place (regardless of where the first MergedCellsRecord was found */ // put merged cells table in the right place (regardless of where the first MergedCellsRecord was found */
RecordOrderer.addNewSheetRecord(records, retval._mergedCellsTable); RecordOrderer.addNewSheetRecord(records, _mergedCellsTable);
retval.records = records;
if (log.check( POILogger.DEBUG )) if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "sheet createSheet (existing file) exited"); log.log(POILogger.DEBUG, "sheet createSheet (existing file) exited");
return retval;
} }
private static final class RecordCloner implements RecordVisitor { private static final class RecordCloner implements RecordVisitor {
@ -361,7 +343,7 @@ public final class Sheet implements Model {
* belongs to a sheet. * belongs to a sheet.
*/ */
public Sheet cloneSheet() { public Sheet cloneSheet() {
ArrayList clonedRecords = new ArrayList(this.records.size()); List clonedRecords = new ArrayList(this.records.size());
for (int i = 0; i < this.records.size(); i++) { for (int i = 0; i < this.records.size(); i++) {
RecordBase rb = (RecordBase) this.records.get(i); RecordBase rb = (RecordBase) this.records.get(i);
if (rb instanceof RecordAggregate) { if (rb instanceof RecordAggregate) {
@ -371,25 +353,7 @@ public final class Sheet implements Model {
Record rec = (Record) ((Record) rb).clone(); Record rec = (Record) ((Record) rb).clone();
clonedRecords.add(rec); clonedRecords.add(rec);
} }
return createSheet(clonedRecords, 0, 0); return createSheet(new RecordStream(clonedRecords, 0));
}
/**
* read support (offset = 0) Same as createSheet(Record[] recs, int, int)
* only the record offset is assumed to be 0.
*
* @param records array containing those records in the sheet in sequence (normally obtained from RecordFactory)
* @param sheetnum integer specifying the sheet's number (0,1 or 2 in this release)
* @return Sheet object
*/
public static Sheet createSheet(List records, int sheetnum)
{
if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG,
"Sheet createSheet (exisiting file) assumed offset 0");
return createSheet(records, sheetnum, 0);
} }
/** /**
@ -399,19 +363,18 @@ public final class Sheet implements Model {
* *
* @return Sheet object with all values set to defaults * @return Sheet object with all values set to defaults
*/ */
public static Sheet createSheet() {
public static Sheet createSheet() return new Sheet();
{ }
// TODO - convert this method to a constructor private Sheet() {
_mergedCellsTable = new MergedCellsTable();
records = new ArrayList(32);
if (log.check( POILogger.DEBUG )) if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "Sheet createsheet from scratch called"); log.log(POILogger.DEBUG, "Sheet createsheet from scratch called");
Sheet retval = new Sheet();
ArrayList records = new ArrayList(30);
records.add(createBOF()); records.add(createBOF());
// records.add(retval.createIndex());
records.add(createCalcMode()); records.add(createCalcMode());
records.add(createCalcCount() ); records.add(createCalcCount() );
records.add(createRefMode() ); records.add(createRefMode() );
@ -419,50 +382,46 @@ public final class Sheet implements Model {
records.add(createDelta() ); records.add(createDelta() );
records.add(createSaveRecalc() ); records.add(createSaveRecalc() );
records.add(createPrintHeaders() ); records.add(createPrintHeaders() );
retval.printGridlines = createPrintGridlines(); printGridlines = createPrintGridlines();
records.add( retval.printGridlines ); records.add( printGridlines );
retval.gridset = createGridset(); gridset = createGridset();
records.add( retval.gridset ); records.add( gridset );
retval._gutsRecord = createGuts(); _gutsRecord = createGuts();
records.add( retval._gutsRecord ); records.add( _gutsRecord );
retval.defaultrowheight = createDefaultRowHeight(); defaultrowheight = createDefaultRowHeight();
records.add( retval.defaultrowheight ); records.add( defaultrowheight );
records.add( retval.createWSBool() ); records.add( createWSBool() );
// 'Page Settings Block' // 'Page Settings Block'
retval._psBlock = new PageSettingsBlock(); _psBlock = new PageSettingsBlock();
records.add(retval._psBlock); records.add(_psBlock);
// 'Worksheet Protection Block' (after 'Page Settings Block' and before DEFCOLWIDTH) // 'Worksheet Protection Block' (after 'Page Settings Block' and before DEFCOLWIDTH)
// PROTECT record normally goes here, don't add yet since the flag is initially false // PROTECT record normally goes here, don't add yet since the flag is initially false
retval.defaultcolwidth = createDefaultColWidth(); defaultcolwidth = createDefaultColWidth();
records.add( retval.defaultcolwidth); records.add( defaultcolwidth);
ColumnInfoRecordsAggregate columns = new ColumnInfoRecordsAggregate(); ColumnInfoRecordsAggregate columns = new ColumnInfoRecordsAggregate();
records.add( columns ); records.add( columns );
retval._columnInfos = columns; _columnInfos = columns;
retval._dimensions = createDimensions(); _dimensions = createDimensions();
records.add(retval._dimensions); records.add(_dimensions);
retval.dimsloc = records.size()-1; _rowsAggregate = new RowRecordsAggregate();
retval._rowsAggregate = new RowRecordsAggregate(); records.add(_rowsAggregate);
records.add(retval._rowsAggregate);
// 'Sheet View Settings' // 'Sheet View Settings'
records.add(retval.windowTwo = retval.createWindowTwo()); records.add(windowTwo = createWindowTwo());
retval.selection = createSelection(); selection = createSelection();
records.add(retval.selection); records.add(selection);
records.add(retval._mergedCellsTable); // MCT comes after 'Sheet View Settings' records.add(_mergedCellsTable); // MCT comes after 'Sheet View Settings'
records.add(EOFRecord.instance); records.add(EOFRecord.instance);
retval.records = records;
if (log.check( POILogger.DEBUG )) if (log.check( POILogger.DEBUG ))
log.log(POILogger.DEBUG, "Sheet createsheet from scratch exit"); log.log(POILogger.DEBUG, "Sheet createsheet from scratch exit");
return retval;
} }
public RowRecordsAggregate getRowsAggregate() { public RowRecordsAggregate getRowsAggregate() {
return _rowsAggregate; return _rowsAggregate;
} }
private MergedCellsTable getMergedRecords() { private MergedCellsTable getMergedRecords() {
@ -470,6 +429,15 @@ public final class Sheet implements Model {
return _mergedCellsTable; return _mergedCellsTable;
} }
/**
* Updates formulas in cells and conditional formats due to moving of cells
* @param externSheetIndex the externSheet index of this sheet
*/
public void updateFormulasAfterCellShift(FormulaShifter shifter, int externSheetIndex) {
getRowsAggregate().updateFormulasAfterRowShift(shifter, externSheetIndex);
getConditionalFormattingTable().updateFormulasAfterCellShift(shifter, externSheetIndex);
// TODO - adjust data validations
}
public int addMergedRegion(int rowFrom, int colFrom, int rowTo, int colTo) { public int addMergedRegion(int rowFrom, int colFrom, int rowTo, int colTo) {
// Validate input // Validate input
@ -509,7 +477,7 @@ public final class Sheet implements Model {
public int getNumMergedRegions() { public int getNumMergedRegions() {
return getMergedRecords().getNumberOfMergedRegions(); return getMergedRecords().getNumberOfMergedRegions();
} }
private ConditionalFormattingTable getConditionalFormattingTable() { public ConditionalFormattingTable getConditionalFormattingTable() {
if (condFormatting == null) { if (condFormatting == null) {
condFormatting = new ConditionalFormattingTable(); condFormatting = new ConditionalFormattingTable();
RecordOrderer.addNewSheetRecord(records, condFormatting); RecordOrderer.addNewSheetRecord(records, condFormatting);
@ -517,24 +485,6 @@ public final class Sheet implements Model {
return condFormatting; return condFormatting;
} }
public int addConditionalFormatting(CFRecordsAggregate cfAggregate) {
ConditionalFormattingTable cft = getConditionalFormattingTable();
return cft.add(cfAggregate);
}
public void removeConditionalFormatting(int index) {
getConditionalFormattingTable().remove(index);
}
public CFRecordsAggregate getCFRecordsAggregateAt(int index) {
return getConditionalFormattingTable().get(index);
}
public int getNumConditionalFormattings() {
return getConditionalFormattingTable().size();
}
/** /**
* Per an earlier reported bug in working with Andy Khan's excel read library. This * Per an earlier reported bug in working with Andy Khan's excel read library. This
* sets the values in the sheet's DimensionsRecord object to be correct. Excel doesn't * sets the values in the sheet's DimensionsRecord object to be correct. Excel doesn't
@ -1367,11 +1317,6 @@ public final class Sheet implements Model {
windowTwo.setSelected(sel); windowTwo.setSelected(sel);
} }
public int getEofLoc()
{
return eofLoc;
}
/** /**
* Creates a split (freezepane). Any existing freezepane or split pane is overwritten. * Creates a split (freezepane). Any existing freezepane or split pane is overwritten.
* @param colSplit Horizonatal position of split. * @param colSplit Horizonatal position of split.
@ -1688,19 +1633,18 @@ public final class Sheet implements Model {
if (_psBlock == null) { if (_psBlock == null) {
_psBlock = new PageSettingsBlock(); _psBlock = new PageSettingsBlock();
RecordOrderer.addNewSheetRecord(records, _psBlock); RecordOrderer.addNewSheetRecord(records, _psBlock);
dimsloc++;
} }
return _psBlock; return _psBlock;
} }
public void setColumnGroupCollapsed(int columnNumber, boolean collapsed) { public void setColumnGroupCollapsed(int columnNumber, boolean collapsed) {
if (collapsed) { if (collapsed) {
_columnInfos.collapseColumn(columnNumber); _columnInfos.collapseColumn(columnNumber);
} else { } else {
_columnInfos.expandColumn(columnNumber); _columnInfos.expandColumn(columnNumber);
} }
} }
/** /**
* protect a spreadsheet with a password (not encypted, just sets protect * protect a spreadsheet with a password (not encypted, just sets protect

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -16,18 +15,13 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
/*
* BlankRecord.java
*
* Created on December 10, 2001, 12:07 PM
*/
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
/** /**
* Title: Blank cell record <P> * Title: Blank cell record (0x0201) <P>
* Description: Represents a column in a row with no value but with styling.<P> * Description: Represents a column in a row with no value but with styling.<P>
* REFERENCE: PG 287 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P> * REFERENCE: PG 287 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
* @author Andrew C. Oliver (acoliver at apache dot org) * @author Andrew C. Oliver (acoliver at apache dot org)
@ -35,13 +29,12 @@ import org.apache.poi.util.LittleEndian;
* @version 2.0-pre * @version 2.0-pre
*/ */
public final class BlankRecord extends Record implements CellValueRecordInterface { public final class BlankRecord extends Record implements CellValueRecordInterface {
public final static short sid = 0x201; public final static short sid = 0x0201;
private int field_1_row; private int field_1_row;
private short field_2_col; private short field_2_col;
private short field_3_xf; private short field_3_xf;
/** Creates a new instance of BlankRecord */ /** Creates a new instance of BlankRecord */
public BlankRecord() public BlankRecord()
{ {
} }
@ -50,7 +43,6 @@ public final class BlankRecord extends Record implements CellValueRecordInterfac
* Constructs a BlankRecord and sets its fields appropriately * Constructs a BlankRecord and sets its fields appropriately
* @param in the RecordInputstream to read the record from * @param in the RecordInputstream to read the record from
*/ */
public BlankRecord(RecordInputStream in) public BlankRecord(RecordInputStream in)
{ {
super(in); super(in);
@ -58,7 +50,6 @@ public final class BlankRecord extends Record implements CellValueRecordInterfac
protected void fillFields(RecordInputStream in) protected void fillFields(RecordInputStream in)
{ {
//field_1_row = LittleEndian.getShort(data, 0 + offset);
field_1_row = in.readUShort(); field_1_row = in.readUShort();
field_2_col = in.readShort(); field_2_col = in.readShort();
field_3_xf = in.readShort(); field_3_xf = in.readShort();
@ -70,7 +61,6 @@ public final class BlankRecord extends Record implements CellValueRecordInterfac
* *
* @param id alleged id for this record * @param id alleged id for this record
*/ */
protected void validateSid(short id) protected void validateSid(short id)
{ {
if (id != sid) if (id != sid)
@ -83,8 +73,6 @@ public final class BlankRecord extends Record implements CellValueRecordInterfac
* set the row this cell occurs on * set the row this cell occurs on
* @param row the row this cell occurs within * @param row the row this cell occurs within
*/ */
//public void setRow(short row)
public void setRow(int row) public void setRow(int row)
{ {
field_1_row = row; field_1_row = row;
@ -95,8 +83,6 @@ public final class BlankRecord extends Record implements CellValueRecordInterfac
* *
* @return the row * @return the row
*/ */
//public short getRow()
public int getRow() public int getRow()
{ {
return field_1_row; return field_1_row;
@ -107,7 +93,6 @@ public final class BlankRecord extends Record implements CellValueRecordInterfac
* *
* @return the column * @return the column
*/ */
public short getColumn() public short getColumn()
{ {
return field_2_col; return field_2_col;
@ -119,7 +104,6 @@ public final class BlankRecord extends Record implements CellValueRecordInterfac
* @param xf - the 0-based index of the extended format * @param xf - the 0-based index of the extended format
* @see org.apache.poi.hssf.record.ExtendedFormatRecord * @see org.apache.poi.hssf.record.ExtendedFormatRecord
*/ */
public void setXFIndex(short xf) public void setXFIndex(short xf)
{ {
field_3_xf = xf; field_3_xf = xf;
@ -130,7 +114,6 @@ public final class BlankRecord extends Record implements CellValueRecordInterfac
* *
* @return extended format index * @return extended format index
*/ */
public short getXFIndex() public short getXFIndex()
{ {
return field_3_xf; return field_3_xf;
@ -147,20 +130,9 @@ public final class BlankRecord extends Record implements CellValueRecordInterfac
field_2_col = col; field_2_col = col;
} }
public boolean isInValueSection()
{
return true;
}
public boolean isValue()
{
return true;
}
/** /**
* return the non static version of the id for this record. * return the non static version of the id for this record.
*/ */
public short getSid() public short getSid()
{ {
return sid; return sid;
@ -168,17 +140,14 @@ public final class BlankRecord extends Record implements CellValueRecordInterfac
public String toString() public String toString()
{ {
StringBuffer buffer = new StringBuffer(); StringBuffer sb = new StringBuffer();
buffer.append("[BLANK]\n"); sb.append("[BLANK]\n");
buffer.append("row = ").append(Integer.toHexString(getRow())) sb.append(" row= ").append(HexDump.shortToHex(getRow())).append("\n");
.append("\n"); sb.append(" col= ").append(HexDump.shortToHex(getColumn())).append("\n");
buffer.append("col = ").append(Integer.toHexString(getColumn())) sb.append(" xf = ").append(HexDump.shortToHex(getXFIndex())).append("\n");
.append("\n"); sb.append("[/BLANK]\n");
buffer.append("xf = ") return sb.toString();
.append(Integer.toHexString(getXFIndex())).append("\n");
buffer.append("[/BLANK]\n");
return buffer.toString();
} }
/** /**
@ -188,15 +157,13 @@ public final class BlankRecord extends Record implements CellValueRecordInterfac
* *
* @return byte array containing instance data * @return byte array containing instance data
*/ */
public int serialize(int offset, byte [] data) public int serialize(int offset, byte [] data)
{ {
LittleEndian.putShort(data, 0 + offset, sid); LittleEndian.putUShort(data, 0 + offset, sid);
LittleEndian.putShort(data, 2 + offset, ( short ) 6); LittleEndian.putUShort(data, 2 + offset, 6);
//LittleEndian.putShort(data, 4 + offset, getRow()); LittleEndian.putUShort(data, 4 + offset, getRow());
LittleEndian.putShort(data, 4 + offset, ( short ) getRow()); LittleEndian.putUShort(data, 6 + offset, getColumn());
LittleEndian.putShort(data, 6 + offset, getColumn()); LittleEndian.putUShort(data, 8 + offset, getXFIndex());
LittleEndian.putShort(data, 8 + offset, getXFIndex());
return getRecordSize(); return getRecordSize();
} }

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -16,25 +15,20 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
/*
* BoolErrRecord.java
*
* Created on January 19, 2002, 9:30 AM
*/
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
/** /**
* Creates new BoolErrRecord. <P> * Creates new BoolErrRecord. (0x0205) <P>
* REFERENCE: PG ??? Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P> * REFERENCE: PG ??? Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
* @author Michael P. Harhen * @author Michael P. Harhen
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre * @version 2.0-pre
*/ */
public final class BoolErrRecord extends Record implements CellValueRecordInterface { public final class BoolErrRecord extends Record implements CellValueRecordInterface {
public final static short sid = 0x205; public final static short sid = 0x0205;
private int field_1_row; private int field_1_row;
private short field_2_column; private short field_2_column;
private short field_3_xf_index; private short field_3_xf_index;
@ -51,7 +45,6 @@ public final class BoolErrRecord extends Record implements CellValueRecordInterf
* *
* @param in the RecordInputstream to read the record from * @param in the RecordInputstream to read the record from
*/ */
public BoolErrRecord(RecordInputStream in) public BoolErrRecord(RecordInputStream in)
{ {
super(in); super(in);
@ -60,7 +53,6 @@ public final class BoolErrRecord extends Record implements CellValueRecordInterf
/** /**
* @param in the RecordInputstream to read the record from * @param in the RecordInputstream to read the record from
*/ */
protected void fillFields(RecordInputStream in) protected void fillFields(RecordInputStream in)
{ {
//field_1_row = LittleEndian.getShort(data, 0 + offset); //field_1_row = LittleEndian.getShort(data, 0 + offset);
@ -71,7 +63,6 @@ public final class BoolErrRecord extends Record implements CellValueRecordInterf
field_5_fError = in.readByte(); field_5_fError = in.readByte();
} }
//public void setRow(short row)
public void setRow(int row) public void setRow(int row)
{ {
field_1_row = row; field_1_row = row;
@ -87,7 +78,6 @@ public final class BoolErrRecord extends Record implements CellValueRecordInterf
* @see org.apache.poi.hssf.record.ExtendedFormatRecord * @see org.apache.poi.hssf.record.ExtendedFormatRecord
* @param xf index to the XF record * @param xf index to the XF record
*/ */
public void setXFIndex(short xf) public void setXFIndex(short xf)
{ {
field_3_xf_index = xf; field_3_xf_index = xf;
@ -98,7 +88,6 @@ public final class BoolErrRecord extends Record implements CellValueRecordInterf
* *
* @param value representing the boolean value * @param value representing the boolean value
*/ */
public void setValue(boolean value) public void setValue(boolean value)
{ {
field_4_bBoolErr = value ? ( byte ) 1 field_4_bBoolErr = value ? ( byte ) 1
@ -113,7 +102,6 @@ public final class BoolErrRecord extends Record implements CellValueRecordInterf
* this value can only be 0,7,15,23,29,36 or 42 * this value can only be 0,7,15,23,29,36 or 42
* see bugzilla bug 16560 for an explanation * see bugzilla bug 16560 for an explanation
*/ */
public void setValue(byte value) public void setValue(byte value)
{ {
if ( (value==0)||(value==7)||(value==15)||(value==23)||(value==29)||(value==36)||(value==42)) { if ( (value==0)||(value==7)||(value==15)||(value==23)||(value==29)||(value==36)||(value==42)) {
@ -124,7 +112,6 @@ public final class BoolErrRecord extends Record implements CellValueRecordInterf
} }
} }
//public short getRow()
public int getRow() public int getRow()
{ {
return field_1_row; return field_1_row;
@ -140,7 +127,6 @@ public final class BoolErrRecord extends Record implements CellValueRecordInterf
* @see org.apache.poi.hssf.record.ExtendedFormatRecord * @see org.apache.poi.hssf.record.ExtendedFormatRecord
* @return index to the XF record * @return index to the XF record
*/ */
public short getXFIndex() public short getXFIndex()
{ {
return field_3_xf_index; return field_3_xf_index;
@ -151,7 +137,6 @@ public final class BoolErrRecord extends Record implements CellValueRecordInterf
* *
* @return boolean representing the boolean value * @return boolean representing the boolean value
*/ */
public boolean getBooleanValue() public boolean getBooleanValue()
{ {
return (field_4_bBoolErr != 0); return (field_4_bBoolErr != 0);
@ -162,7 +147,6 @@ public final class BoolErrRecord extends Record implements CellValueRecordInterf
* *
* @return byte representing the error value * @return byte representing the error value
*/ */
public byte getErrorValue() public byte getErrorValue()
{ {
return field_4_bBoolErr; return field_4_bBoolErr;
@ -173,7 +157,6 @@ public final class BoolErrRecord extends Record implements CellValueRecordInterf
* *
* @return boolean true if the cell holds a boolean value * @return boolean true if the cell holds a boolean value
*/ */
public boolean isBoolean() public boolean isBoolean()
{ {
return (field_5_fError == ( byte ) 0); return (field_5_fError == ( byte ) 0);
@ -194,32 +177,24 @@ public final class BoolErrRecord extends Record implements CellValueRecordInterf
public boolean isError() public boolean isError()
{ {
return (field_5_fError != ( byte ) 0); return field_5_fError != 0;
} }
public String toString() public String toString()
{ {
StringBuffer buffer = new StringBuffer(); StringBuffer sb = new StringBuffer();
buffer.append("[BOOLERR]\n"); sb.append("[BOOLERR]\n");
buffer.append(" .row = ") sb.append(" .row = ").append(HexDump.shortToHex(getRow())).append("\n");
.append(Integer.toHexString(getRow())).append("\n"); sb.append(" .col = ").append(HexDump.shortToHex(getColumn())).append("\n");
buffer.append(" .col = ") sb.append(" .xfindex= ").append(HexDump.shortToHex(getXFIndex())).append("\n");
.append(Integer.toHexString(getColumn())).append("\n"); if (isBoolean()) {
buffer.append(" .xfindex = ") sb.append(" .booleanValue = ").append(getBooleanValue()).append("\n");
.append(Integer.toHexString(getXFIndex())).append("\n"); } else {
if (isBoolean()) sb.append(" .errorValue = ").append(getErrorValue()).append("\n");
{
buffer.append(" .booleanValue = ").append(getBooleanValue())
.append("\n");
} }
else sb.append("[/BOOLERR]\n");
{ return sb.toString();
buffer.append(" .errorValue = ").append(getErrorValue())
.append("\n");
}
buffer.append("[/BOOLERR]\n");
return buffer.toString();
} }
/** /**
@ -229,15 +204,13 @@ public final class BoolErrRecord extends Record implements CellValueRecordInterf
* *
* @return byte array containing instance data * @return byte array containing instance data
*/ */
public int serialize(int offset, byte [] data) public int serialize(int offset, byte [] data)
{ {
LittleEndian.putShort(data, 0 + offset, sid); LittleEndian.putUShort(data, 0 + offset, sid);
LittleEndian.putShort(data, 2 + offset, ( short ) 8); LittleEndian.putUShort(data, 2 + offset, 8);
//LittleEndian.putShort(data, 4 + offset, getRow()); LittleEndian.putUShort(data, 4 + offset, getRow());
LittleEndian.putShort(data, 4 + offset, ( short ) getRow()); LittleEndian.putUShort(data, 6 + offset, getColumn());
LittleEndian.putShort(data, 6 + offset, getColumn()); LittleEndian.putUShort(data, 8 + offset, getXFIndex());
LittleEndian.putShort(data, 8 + offset, getXFIndex());
data[ 10 + offset ] = field_4_bBoolErr; data[ 10 + offset ] = field_4_bBoolErr;
data[ 11 + offset ] = field_5_fError; data[ 11 + offset ] = field_5_fError;
return getRecordSize(); return getRecordSize();
@ -254,7 +227,6 @@ public final class BoolErrRecord extends Record implements CellValueRecordInterf
* *
* @param id alleged id for this record * @param id alleged id for this record
*/ */
protected void validateSid(short id) protected void validateSid(short id)
{ {
if (id != BoolErrRecord.sid) if (id != BoolErrRecord.sid)
@ -268,16 +240,6 @@ public final class BoolErrRecord extends Record implements CellValueRecordInterf
return sid; return sid;
} }
public boolean isInValueSection()
{
return true;
}
public boolean isValue()
{
return true;
}
public Object clone() { public Object clone() {
BoolErrRecord rec = new BoolErrRecord(); BoolErrRecord rec = new BoolErrRecord();
rec.field_1_row = field_1_row; rec.field_1_row = field_1_row;

View File

@ -420,6 +420,15 @@ public final class CFRuleRecord extends Record {
{ {
return field_17_formula1; return field_17_formula1;
} }
public void setParsedExpression1(Ptg[] ptgs) {
field_17_formula1 = safeClone(ptgs);
}
private static Ptg[] safeClone(Ptg[] ptgs) {
if (ptgs == null) {
return null;
}
return (Ptg[]) ptgs.clone();
}
/** /**
* get the stack of the 2nd expression as a list * get the stack of the 2nd expression as a list
@ -434,6 +443,9 @@ public final class CFRuleRecord extends Record {
{ {
return field_18_formula2; return field_18_formula2;
} }
public void setParsedExpression2(Ptg[] ptgs) {
field_18_formula2 = safeClone(ptgs);
}
/** /**
* called by constructor, should throw runtime exception in the event of a * called by constructor, should throw runtime exception in the event of a

View File

@ -182,10 +182,6 @@ public final class DBCellRecord extends Record {
return sid; return sid;
} }
public boolean isInValueSection()
{
return true;
}
public Object clone() { public Object clone() {
// TODO - make immutable. // TODO - make immutable.
// this should be safe because only the instantiating code mutates these objects // this should be safe because only the instantiating code mutates these objects

View File

@ -406,14 +406,6 @@ public final class FormulaRecord extends Record implements CellValueRecordInterf
return 4 + getDataSize(); return 4 + getDataSize();
} }
public boolean isInValueSection() {
return true;
}
public boolean isValue() {
return true;
}
public String toString() { public String toString() {
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();

View File

@ -17,8 +17,10 @@
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.HexDump;
/** /**
* Label Record - read only support for strings stored directly in the cell.. Don't * Label Record (0x0204) - read only support for strings stored directly in the cell.. Don't
* use this (except to read), use LabelSST instead <P> * use this (except to read), use LabelSST instead <P>
* REFERENCE: PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P> * REFERENCE: PG 325 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
* @author Andrew C. Oliver (acoliver at apache dot org) * @author Andrew C. Oliver (acoliver at apache dot org)
@ -27,7 +29,7 @@ package org.apache.poi.hssf.record;
* @see org.apache.poi.hssf.record.LabelSSTRecord * @see org.apache.poi.hssf.record.LabelSSTRecord
*/ */
public final class LabelRecord extends Record implements CellValueRecordInterface { public final class LabelRecord extends Record implements CellValueRecordInterface {
public final static short sid = 0x204; public final static short sid = 0x0204;
private int field_1_row; private int field_1_row;
private short field_2_column; private short field_2_column;
@ -37,7 +39,6 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
private String field_6_value; private String field_6_value;
/** Creates new LabelRecord */ /** Creates new LabelRecord */
public LabelRecord() public LabelRecord()
{ {
} }
@ -47,7 +48,6 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
* *
* @param in the RecordInputstream to read the record from * @param in the RecordInputstream to read the record from
*/ */
public LabelRecord(RecordInputStream in) public LabelRecord(RecordInputStream in)
{ {
super(in); super(in);
@ -59,7 +59,6 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
* *
* @param id alleged id for this record * @param id alleged id for this record
*/ */
protected void validateSid(short id) protected void validateSid(short id)
{ {
if (id != sid) if (id != sid)
@ -71,7 +70,6 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
/** /**
* @param in the RecordInputstream to read the record from * @param in the RecordInputstream to read the record from
*/ */
protected void fillFields(RecordInputStream in) protected void fillFields(RecordInputStream in)
{ {
field_1_row = in.readUShort(); field_1_row = in.readUShort();
@ -92,11 +90,6 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
/* /*
* READ ONLY ACCESS... THIS IS FOR COMPATIBILITY ONLY...USE LABELSST! public * READ ONLY ACCESS... THIS IS FOR COMPATIBILITY ONLY...USE LABELSST! public
* void setRow(short row) { field_1_row = row; }
*
* public void setColumn(short col) { field_2_column = col; }
*
* public void setXFIndex(short index) { field_3_xf_index = index; }
*/ */
public int getRow() public int getRow()
{ {
@ -117,7 +110,6 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
* get the number of characters this string contains * get the number of characters this string contains
* @return number of characters * @return number of characters
*/ */
public short getStringLength() public short getStringLength()
{ {
return field_4_string_len; return field_4_string_len;
@ -127,7 +119,6 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
* is this uncompressed unicode (16bit)? Or just 8-bit compressed? * is this uncompressed unicode (16bit)? Or just 8-bit compressed?
* @return isUnicode - True for 16bit- false for 8bit * @return isUnicode - True for 16bit- false for 8bit
*/ */
public boolean isUnCompressedUnicode() public boolean isUnCompressedUnicode()
{ {
return (field_5_unicode_flag == 1); return (field_5_unicode_flag == 1);
@ -139,7 +130,6 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
* @return the text string * @return the text string
* @see #getStringLength() * @see #getStringLength()
*/ */
public String getValue() public String getValue()
{ {
return field_6_value; return field_6_value;
@ -148,7 +138,6 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
/** /**
* THROWS A RUNTIME EXCEPTION.. USE LABELSSTRecords. YOU HAVE NO REASON to use LABELRecord!! * THROWS A RUNTIME EXCEPTION.. USE LABELSSTRecords. YOU HAVE NO REASON to use LABELRecord!!
*/ */
public int serialize(int offset, byte [] data) public int serialize(int offset, byte [] data)
{ {
throw new RecordFormatException( throw new RecordFormatException(
@ -162,38 +151,21 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
public String toString() public String toString()
{ {
StringBuffer buffer = new StringBuffer(); StringBuffer sb = new StringBuffer();
buffer.append("[LABEL]\n"); sb.append("[LABEL]\n");
buffer.append(" .row = ") sb.append(" .row = ").append(HexDump.shortToHex(getRow())).append("\n");
.append(Integer.toHexString(getRow())).append("\n"); sb.append(" .column = ").append(HexDump.shortToHex(getColumn())).append("\n");
buffer.append(" .column = ") sb.append(" .xfindex = ").append(HexDump.shortToHex(getXFIndex())).append("\n");
.append(Integer.toHexString(getColumn())).append("\n"); sb.append(" .string_len= ").append(HexDump.shortToHex(field_4_string_len)).append("\n");
buffer.append(" .xfindex = ") sb.append(" .unicode_flag= ").append(HexDump.byteToHex(field_5_unicode_flag)).append("\n");
.append(Integer.toHexString(getXFIndex())).append("\n"); sb.append(" .value = ").append(getValue()).append("\n");
buffer.append(" .string_len = ") sb.append("[/LABEL]\n");
.append(Integer.toHexString(field_4_string_len)).append("\n"); return sb.toString();
buffer.append(" .unicode_flag = ")
.append(Integer.toHexString(field_5_unicode_flag)).append("\n");
buffer.append(" .value = ")
.append(getValue()).append("\n");
buffer.append("[/LABEL]\n");
return buffer.toString();
}
public boolean isInValueSection()
{
return true;
}
public boolean isValue()
{
return true;
} }
/** /**
* NO-OP! * NO-OP!
*/ */
public void setColumn(short col) public void setColumn(short col)
{ {
} }
@ -201,8 +173,6 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
/** /**
* NO-OP! * NO-OP!
*/ */
//public void setRow(short row)
public void setRow(int row) public void setRow(int row)
{ {
} }
@ -210,7 +180,6 @@ public final class LabelRecord extends Record implements CellValueRecordInterfac
/** /**
* no op! * no op!
*/ */
public void setXFIndex(short xf) public void setXFIndex(short xf)
{ {
} }

View File

@ -17,6 +17,7 @@
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
/** /**
@ -30,10 +31,10 @@ import org.apache.poi.util.LittleEndian;
*/ */
public final class LabelSSTRecord extends Record implements CellValueRecordInterface { public final class LabelSSTRecord extends Record implements CellValueRecordInterface {
public final static short sid = 0xfd; public final static short sid = 0xfd;
private int field_1_row; private int field_1_row;
private short field_2_column; private int field_2_column;
private short field_3_xf_index; private int field_3_xf_index;
private int field_4_sst_index; private int field_4_sst_index;
public LabelSSTRecord() public LabelSSTRecord()
{ {
@ -43,7 +44,6 @@ public final class LabelSSTRecord extends Record implements CellValueRecordInter
* Constructs an LabelSST record and sets its fields appropriately. * Constructs an LabelSST record and sets its fields appropriately.
* @param in the RecordInputstream to read the record from * @param in the RecordInputstream to read the record from
*/ */
public LabelSSTRecord(RecordInputStream in) public LabelSSTRecord(RecordInputStream in)
{ {
super(in); super(in);
@ -60,14 +60,12 @@ public final class LabelSSTRecord extends Record implements CellValueRecordInter
protected void fillFields(RecordInputStream in) protected void fillFields(RecordInputStream in)
{ {
//field_1_row = LittleEndian.getShort(data, 0 + offset);
field_1_row = in.readUShort(); field_1_row = in.readUShort();
field_2_column = in.readShort(); field_2_column = in.readUShort();
field_3_xf_index = in.readShort(); field_3_xf_index = in.readUShort();
field_4_sst_index = in.readInt(); field_4_sst_index = in.readInt();
} }
//public void setRow(short row)
public void setRow(int row) public void setRow(int row)
{ {
field_1_row = row; field_1_row = row;
@ -102,7 +100,6 @@ public final class LabelSSTRecord extends Record implements CellValueRecordInter
field_4_sst_index = index; field_4_sst_index = index;
} }
//public short getRow()
public int getRow() public int getRow()
{ {
return field_1_row; return field_1_row;
@ -110,7 +107,7 @@ public final class LabelSSTRecord extends Record implements CellValueRecordInter
public short getColumn() public short getColumn()
{ {
return field_2_column; return (short)field_2_column;
} }
/** /**
@ -122,7 +119,7 @@ public final class LabelSSTRecord extends Record implements CellValueRecordInter
public short getXFIndex() public short getXFIndex()
{ {
return field_3_xf_index; return (short)field_3_xf_index;
} }
/** /**
@ -139,29 +136,24 @@ public final class LabelSSTRecord extends Record implements CellValueRecordInter
public String toString() public String toString()
{ {
StringBuffer buffer = new StringBuffer(); StringBuffer sb = new StringBuffer();
buffer.append("[LABELSST]\n"); sb.append("[LABELSST]\n");
buffer.append(" .row = ") sb.append(" .row = ").append(HexDump.shortToHex(getRow())).append("\n");
.append(Integer.toHexString(getRow())).append("\n"); sb.append(" .column = ").append(HexDump.shortToHex(getColumn())).append("\n");
buffer.append(" .column = ") sb.append(" .xfindex = ").append(HexDump.shortToHex(getXFIndex())).append("\n");
.append(Integer.toHexString(getColumn())).append("\n"); sb.append(" .sstindex= ").append(HexDump.intToHex(getSSTIndex())).append("\n");
buffer.append(" .xfindex = ") sb.append("[/LABELSST]\n");
.append(Integer.toHexString(getXFIndex())).append("\n"); return sb.toString();
buffer.append(" .sstindex = ")
.append(Integer.toHexString(getSSTIndex())).append("\n");
buffer.append("[/LABELSST]\n");
return buffer.toString();
} }
public int serialize(int offset, byte [] data) public int serialize(int offset, byte [] data)
{ {
LittleEndian.putShort(data, 0 + offset, sid); LittleEndian.putUShort(data, 0 + offset, sid);
LittleEndian.putShort(data, 2 + offset, ( short ) 10); LittleEndian.putUShort(data, 2 + offset, 10);
//LittleEndian.putShort(data, 4 + offset, getRow()); LittleEndian.putUShort(data, 4 + offset, getRow());
LittleEndian.putShort(data, 4 + offset, ( short )getRow()); LittleEndian.putUShort(data, 6 + offset, getColumn());
LittleEndian.putShort(data, 6 + offset, getColumn()); LittleEndian.putUShort(data, 8 + offset, getXFIndex());
LittleEndian.putShort(data, 8 + offset, getXFIndex());
LittleEndian.putInt(data, 10 + offset, getSSTIndex()); LittleEndian.putInt(data, 10 + offset, getSSTIndex());
return getRecordSize(); return getRecordSize();
} }
@ -176,16 +168,6 @@ public final class LabelSSTRecord extends Record implements CellValueRecordInter
return sid; return sid;
} }
public boolean isInValueSection()
{
return true;
}
public boolean isValue()
{
return true;
}
public Object clone() { public Object clone() {
LabelSSTRecord rec = new LabelSSTRecord(); LabelSSTRecord rec = new LabelSSTRecord();
rec.field_1_row = field_1_row; rec.field_1_row = field_1_row;

View File

@ -17,22 +17,23 @@
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.Record;
/** /**
* Contains a numeric cell value. <P> * NUMBER (0x0203) Contains a numeric cell value. <P>
* REFERENCE: PG 334 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P> * REFERENCE: PG 334 Microsoft Excel 97 Developer's Kit (ISBN: 1-57231-498-2)<P>
* @author Andrew C. Oliver (acoliver at apache dot org) * @author Andrew C. Oliver (acoliver at apache dot org)
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre * @version 2.0-pre
*/ */
public final class NumberRecord extends Record implements CellValueRecordInterface { public final class NumberRecord extends Record implements CellValueRecordInterface {
public static final short sid = 0x203; public static final short sid = 0x0203;
private int field_1_row; private int field_1_row;
private short field_2_col; private int field_2_col;
private short field_3_xf; private int field_3_xf;
private double field_4_value; private double field_4_value;
/** Creates new NumberRecord */ /** Creates new NumberRecord */
public NumberRecord() public NumberRecord()
@ -44,7 +45,6 @@ public final class NumberRecord extends Record implements CellValueRecordInterfa
* *
* @param in the RecordInputstream to read the record from * @param in the RecordInputstream to read the record from
*/ */
public NumberRecord(RecordInputStream in) public NumberRecord(RecordInputStream in)
{ {
super(in); super(in);
@ -53,17 +53,14 @@ public final class NumberRecord extends Record implements CellValueRecordInterfa
/** /**
* @param in the RecordInputstream to read the record from * @param in the RecordInputstream to read the record from
*/ */
protected void fillFields(RecordInputStream in) protected void fillFields(RecordInputStream in)
{ {
//field_1_row = LittleEndian.getShort(data, 0 + offset);
field_1_row = in.readUShort(); field_1_row = in.readUShort();
field_2_col = in.readShort(); field_2_col = in.readUShort();
field_3_xf = in.readShort(); field_3_xf = in.readUShort();
field_4_value = in.readDouble(); field_4_value = in.readDouble();
} }
//public void setRow(short row)
public void setRow(int row) public void setRow(int row)
{ {
field_1_row = row; field_1_row = row;
@ -79,7 +76,6 @@ public final class NumberRecord extends Record implements CellValueRecordInterfa
* @see org.apache.poi.hssf.record.ExtendedFormatRecord * @see org.apache.poi.hssf.record.ExtendedFormatRecord
* @param xf index to the XF record * @param xf index to the XF record
*/ */
public void setXFIndex(short xf) public void setXFIndex(short xf)
{ {
field_3_xf = xf; field_3_xf = xf;
@ -90,13 +86,11 @@ public final class NumberRecord extends Record implements CellValueRecordInterfa
* *
* @param value double representing the value * @param value double representing the value
*/ */
public void setValue(double value) public void setValue(double value)
{ {
field_4_value = value; field_4_value = value;
} }
//public short getRow()
public int getRow() public int getRow()
{ {
return field_1_row; return field_1_row;
@ -104,7 +98,7 @@ public final class NumberRecord extends Record implements CellValueRecordInterfa
public short getColumn() public short getColumn()
{ {
return field_2_col; return (short)field_2_col;
} }
/** /**
@ -112,10 +106,9 @@ public final class NumberRecord extends Record implements CellValueRecordInterfa
* @see org.apache.poi.hssf.record.ExtendedFormatRecord * @see org.apache.poi.hssf.record.ExtendedFormatRecord
* @return index to the XF record * @return index to the XF record
*/ */
public short getXFIndex() public short getXFIndex()
{ {
return field_3_xf; return (short)field_3_xf;
} }
/** /**
@ -123,7 +116,6 @@ public final class NumberRecord extends Record implements CellValueRecordInterfa
* *
* @return double representing the value * @return double representing the value
*/ */
public double getValue() public double getValue()
{ {
return field_4_value; return field_4_value;
@ -131,19 +123,15 @@ public final class NumberRecord extends Record implements CellValueRecordInterfa
public String toString() public String toString()
{ {
StringBuffer buffer = new StringBuffer(); StringBuffer sb = new StringBuffer();
buffer.append("[NUMBER]\n"); sb.append("[NUMBER]\n");
buffer.append(" .row = ") sb.append(" .row = ").append(HexDump.shortToHex(getRow())).append("\n");
.append(Integer.toHexString(getRow())).append("\n"); sb.append(" .col = ").append(HexDump.shortToHex(getColumn())).append("\n");
buffer.append(" .col = ") sb.append(" .xfindex= ").append(HexDump.shortToHex(getXFIndex())).append("\n");
.append(Integer.toHexString(getColumn())).append("\n"); sb.append(" .value = ").append(getValue()).append("\n");
buffer.append(" .xfindex = ") sb.append("[/NUMBER]\n");
.append(Integer.toHexString(getXFIndex())).append("\n"); return sb.toString();
buffer.append(" .value = ").append(getValue())
.append("\n");
buffer.append("[/NUMBER]\n");
return buffer.toString();
} }
/** /**
@ -153,15 +141,13 @@ public final class NumberRecord extends Record implements CellValueRecordInterfa
* *
* @return byte array containing instance data * @return byte array containing instance data
*/ */
public int serialize(int offset, byte [] data) public int serialize(int offset, byte [] data)
{ {
LittleEndian.putShort(data, 0 + offset, sid); LittleEndian.putUShort(data, 0 + offset, sid);
LittleEndian.putShort(data, 2 + offset, ( short ) 14); LittleEndian.putUShort(data, 2 + offset, 14);
//LittleEndian.putShort(data, 4 + offset, getRow()); LittleEndian.putUShort(data, 4 + offset, getRow());
LittleEndian.putShort(data, 4 + offset, ( short ) getRow()); LittleEndian.putUShort(data, 6 + offset, getColumn());
LittleEndian.putShort(data, 6 + offset, getColumn()); LittleEndian.putUShort(data, 8 + offset, getXFIndex());
LittleEndian.putShort(data, 8 + offset, getXFIndex());
LittleEndian.putDouble(data, 10 + offset, getValue()); LittleEndian.putDouble(data, 10 + offset, getValue());
return getRecordSize(); return getRecordSize();
} }
@ -191,16 +177,6 @@ public final class NumberRecord extends Record implements CellValueRecordInterfa
return sid; return sid;
} }
public boolean isInValueSection()
{
return true;
}
public boolean isValue()
{
return true;
}
public Object clone() { public Object clone() {
NumberRecord rec = new NumberRecord(); NumberRecord rec = new NumberRecord();
rec.field_1_row = field_1_row; rec.field_1_row = field_1_row;

View File

@ -18,9 +18,10 @@
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.hssf.util.RKUtil; import org.apache.poi.hssf.util.RKUtil;
import org.apache.poi.util.HexDump;
/** /**
* Title: RK Record * Title: RK Record (0x027E)
* Description: An internal 32 bit number with the two most significant bits * Description: An internal 32 bit number with the two most significant bits
* storing the type. This is part of a bizarre scheme to save disk * storing the type. This is part of a bizarre scheme to save disk
* space and memory (gee look at all the other whole records that * space and memory (gee look at all the other whole records that
@ -37,15 +38,15 @@ import org.apache.poi.hssf.util.RKUtil;
* @see org.apache.poi.hssf.record.NumberRecord * @see org.apache.poi.hssf.record.NumberRecord
*/ */
public final class RKRecord extends Record implements CellValueRecordInterface { public final class RKRecord extends Record implements CellValueRecordInterface {
public final static short sid = 0x27e; public final static short sid = 0x027E;
public final static short RK_IEEE_NUMBER = 0; public final static short RK_IEEE_NUMBER = 0;
public final static short RK_IEEE_NUMBER_TIMES_100 = 1; public final static short RK_IEEE_NUMBER_TIMES_100 = 1;
public final static short RK_INTEGER = 2; public final static short RK_INTEGER = 2;
public final static short RK_INTEGER_TIMES_100 = 3; public final static short RK_INTEGER_TIMES_100 = 3;
private int field_1_row; private int field_1_row;
private short field_2_col; private int field_2_col;
private short field_3_xf_index; private int field_3_xf_index;
private int field_4_rk_number; private int field_4_rk_number;
public RKRecord() public RKRecord()
{ {
@ -55,7 +56,6 @@ public final class RKRecord extends Record implements CellValueRecordInterface {
* Constructs a RK record and sets its fields appropriately. * Constructs a RK record and sets its fields appropriately.
* @param in the RecordInputstream to read the record from * @param in the RecordInputstream to read the record from
*/ */
public RKRecord(RecordInputStream in) public RKRecord(RecordInputStream in)
{ {
super(in); super(in);
@ -71,14 +71,12 @@ public final class RKRecord extends Record implements CellValueRecordInterface {
protected void fillFields(RecordInputStream in) protected void fillFields(RecordInputStream in)
{ {
//field_1_row = LittleEndian.getShort(data, 0 + offset);
field_1_row = in.readUShort(); field_1_row = in.readUShort();
field_2_col = in.readShort(); field_2_col = in.readUShort();
field_3_xf_index = in.readShort(); field_3_xf_index = in.readUShort();
field_4_rk_number = in.readInt(); field_4_rk_number = in.readInt();
} }
//public short getRow()
public int getRow() public int getRow()
{ {
return field_1_row; return field_1_row;
@ -86,12 +84,12 @@ public final class RKRecord extends Record implements CellValueRecordInterface {
public short getColumn() public short getColumn()
{ {
return field_2_col; return (short) field_2_col;
} }
public short getXFIndex() public short getXFIndex()
{ {
return field_3_xf_index; return (short) field_3_xf_index;
} }
public int getRKField() public int getRKField()
@ -110,7 +108,6 @@ public final class RKRecord extends Record implements CellValueRecordInterface {
* <LI>RK_INTEGER_TIMES_100</LI> * <LI>RK_INTEGER_TIMES_100</LI>
* </OL> * </OL>
*/ */
public short getRKType() public short getRKType()
{ {
return ( short ) (field_4_rk_number & 3); return ( short ) (field_4_rk_number & 3);
@ -133,7 +130,6 @@ public final class RKRecord extends Record implements CellValueRecordInterface {
* @return the value as a proper double (hey, it <B>could</B> * @return the value as a proper double (hey, it <B>could</B>
* happen) * happen)
*/ */
public double getRKNumber() public double getRKNumber()
{ {
return RKUtil.decodeNumber(field_4_rk_number); return RKUtil.decodeNumber(field_4_rk_number);
@ -142,26 +138,20 @@ public final class RKRecord extends Record implements CellValueRecordInterface {
public String toString() public String toString()
{ {
StringBuffer buffer = new StringBuffer(); StringBuffer sb = new StringBuffer();
buffer.append("[RK]\n"); sb.append("[RK]\n");
buffer.append(" .row = ") sb.append(" .row = ").append(HexDump.shortToHex(getRow())).append("\n");
.append(Integer.toHexString(getRow())).append("\n"); sb.append(" .col = ").append(HexDump.shortToHex(getColumn())).append("\n");
buffer.append(" .col = ") sb.append(" .xfindex = ").append(HexDump.shortToHex(getXFIndex())).append("\n");
.append(Integer.toHexString(getColumn())).append("\n"); sb.append(" .rknumber = ").append(HexDump.intToHex(getRKField())).append("\n");
buffer.append(" .xfindex = ") sb.append(" .rktype = ").append(HexDump.byteToHex(getRKType())).append("\n");
.append(Integer.toHexString(getXFIndex())).append("\n"); sb.append(" .rknumber= ").append(getRKNumber()).append("\n");
buffer.append(" .rknumber = ") sb.append("[/RK]\n");
.append(Integer.toHexString(getRKField())).append("\n"); return sb.toString();
buffer.append(" .rktype = ")
.append(Integer.toHexString(getRKType())).append("\n");
buffer.append(" .rknumber = ").append(getRKNumber())
.append("\n");
buffer.append("[/RK]\n");
return buffer.toString();
} }
//temporarily just constructs a new number record and returns its value // temporarily just constructs a new number record and returns its value
public int serialize(int offset, byte [] data) public int serialize(int offset, byte [] data)
{ {
NumberRecord rec = new NumberRecord(); NumberRecord rec = new NumberRecord();
@ -209,21 +199,10 @@ public final class RKRecord extends Record implements CellValueRecordInterface {
return sid; return sid;
} }
public boolean isInValueSection()
{
return true;
}
public boolean isValue()
{
return true;
}
public void setColumn(short col) public void setColumn(short col)
{ {
} }
//public void setRow(short row)
public void setRow(int row) public void setRow(int row)
{ {
} }

View File

@ -98,24 +98,6 @@ public abstract class Record extends RecordBase {
return serialize().length; return serialize().length;
} }
/**
* tells whether this type of record contains a value
*/
public boolean isValue()
{
return false;
}
/**
* DBCELL, ROW, VALUES all say yes
*/
public boolean isInValueSection()
{
return false;
}
/** /**
* get a string representation of the record (for biffview/debugging) * get a string representation of the record (for biffview/debugging)
*/ */

View File

@ -19,6 +19,7 @@ package org.apache.poi.hssf.record;
import org.apache.poi.util.BitField; import org.apache.poi.util.BitField;
import org.apache.poi.util.BitFieldFactory; import org.apache.poi.util.BitFieldFactory;
import org.apache.poi.util.HexDump;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
/** /**
@ -29,7 +30,7 @@ import org.apache.poi.util.LittleEndian;
* @author Jason Height (jheight at chariot dot net dot au) * @author Jason Height (jheight at chariot dot net dot au)
* @version 2.0-pre * @version 2.0-pre
*/ */
public final class RowRecord extends Record implements Comparable { public final class RowRecord extends Record {
public final static short sid = 0x0208; public final static short sid = 0x0208;
public static final int ENCODED_SIZE = 20; public static final int ENCODED_SIZE = 20;
@ -77,7 +78,6 @@ public final class RowRecord extends Record implements Comparable {
* Constructs a Row record and sets its fields appropriately. * Constructs a Row record and sets its fields appropriately.
* @param in the RecordInputstream to read the record from * @param in the RecordInputstream to read the record from
*/ */
public RowRecord(RecordInputStream in) public RowRecord(RecordInputStream in)
{ {
super(in); super(in);
@ -107,8 +107,6 @@ public final class RowRecord extends Record implements Comparable {
* set the logical row number for this row (0 based index) * set the logical row number for this row (0 based index)
* @param row - the row number * @param row - the row number
*/ */
//public void setRowNumber(short row)
public void setRowNumber(int row) public void setRowNumber(int row)
{ {
field_1_row_number = row; field_1_row_number = row;
@ -118,7 +116,6 @@ public final class RowRecord extends Record implements Comparable {
* set the logical col number for the first cell this row (0 based index) * set the logical col number for the first cell this row (0 based index)
* @param col - the col number * @param col - the col number
*/ */
public void setFirstCol(short col) public void setFirstCol(short col)
{ {
field_2_first_col = col; field_2_first_col = col;
@ -128,7 +125,6 @@ public final class RowRecord extends Record implements Comparable {
* set the logical col number for the last cell this row (0 based index) * set the logical col number for the last cell this row (0 based index)
* @param col - the col number * @param col - the col number
*/ */
public void setLastCol(short col) public void setLastCol(short col)
{ {
field_3_last_col = col; field_3_last_col = col;
@ -138,7 +134,6 @@ public final class RowRecord extends Record implements Comparable {
* set the height of the row * set the height of the row
* @param height of the row * @param height of the row
*/ */
public void setHeight(short height) public void setHeight(short height)
{ {
field_4_height = height; field_4_height = height;
@ -148,31 +143,17 @@ public final class RowRecord extends Record implements Comparable {
* set whether to optimize or not (set to 0) * set whether to optimize or not (set to 0)
* @param optimize (set to 0) * @param optimize (set to 0)
*/ */
public void setOptimize(short optimize) public void setOptimize(short optimize)
{ {
field_5_optimize = optimize; field_5_optimize = optimize;
} }
/**
* sets the option bitmask. (use the individual bit setters that refer to this
* method)
* @param options - the bitmask
*/
public void setOptionFlags(short options)
{
field_7_option_flags = options | OPTION_BITS_ALWAYS_SET;
}
// option bitfields // option bitfields
/** /**
* set the outline level of this row * set the outline level of this row
* @param ol - the outline level * @param ol - the outline level
* @see #setOptionFlags(short)
*/ */
public void setOutlineLevel(short ol) public void setOutlineLevel(short ol)
{ {
field_7_option_flags = outlineLevel.setValue(field_7_option_flags, ol); field_7_option_flags = outlineLevel.setValue(field_7_option_flags, ol);
@ -181,9 +162,7 @@ public final class RowRecord extends Record implements Comparable {
/** /**
* set whether or not to collapse this row * set whether or not to collapse this row
* @param c - collapse or not * @param c - collapse or not
* @see #setOptionFlags(short)
*/ */
public void setColapsed(boolean c) public void setColapsed(boolean c)
{ {
field_7_option_flags = colapsed.setBoolean(field_7_option_flags, c); field_7_option_flags = colapsed.setBoolean(field_7_option_flags, c);
@ -192,9 +171,7 @@ public final class RowRecord extends Record implements Comparable {
/** /**
* set whether or not to display this row with 0 height * set whether or not to display this row with 0 height
* @param z height is zero or not. * @param z height is zero or not.
* @see #setOptionFlags(short)
*/ */
public void setZeroHeight(boolean z) public void setZeroHeight(boolean z)
{ {
field_7_option_flags = zeroHeight.setBoolean(field_7_option_flags, z); field_7_option_flags = zeroHeight.setBoolean(field_7_option_flags, z);
@ -203,9 +180,7 @@ public final class RowRecord extends Record implements Comparable {
/** /**
* set whether the font and row height are not compatible * set whether the font and row height are not compatible
* @param f true if they aren't compatible (damn not logic) * @param f true if they aren't compatible (damn not logic)
* @see #setOptionFlags(short)
*/ */
public void setBadFontHeight(boolean f) public void setBadFontHeight(boolean f)
{ {
field_7_option_flags = badFontHeight.setBoolean(field_7_option_flags, f); field_7_option_flags = badFontHeight.setBoolean(field_7_option_flags, f);
@ -214,9 +189,7 @@ public final class RowRecord extends Record implements Comparable {
/** /**
* set whether the row has been formatted (even if its got all blank cells) * set whether the row has been formatted (even if its got all blank cells)
* @param f formatted or not * @param f formatted or not
* @see #setOptionFlags(short)
*/ */
public void setFormatted(boolean f) public void setFormatted(boolean f)
{ {
field_7_option_flags = formatted.setBoolean(field_7_option_flags, f); field_7_option_flags = formatted.setBoolean(field_7_option_flags, f);
@ -229,7 +202,6 @@ public final class RowRecord extends Record implements Comparable {
* @see org.apache.poi.hssf.record.ExtendedFormatRecord * @see org.apache.poi.hssf.record.ExtendedFormatRecord
* @param index to the XF record * @param index to the XF record
*/ */
public void setXFIndex(short index) public void setXFIndex(short index)
{ {
field_8_xf_index = index; field_8_xf_index = index;
@ -239,8 +211,6 @@ public final class RowRecord extends Record implements Comparable {
* get the logical row number for this row (0 based index) * get the logical row number for this row (0 based index)
* @return row - the row number * @return row - the row number
*/ */
//public short getRowNumber()
public int getRowNumber() public int getRowNumber()
{ {
return field_1_row_number; return field_1_row_number;
@ -250,7 +220,6 @@ public final class RowRecord extends Record implements Comparable {
* get the logical col number for the first cell this row (0 based index) * get the logical col number for the first cell this row (0 based index)
* @return col - the col number * @return col - the col number
*/ */
public short getFirstCol() public short getFirstCol()
{ {
return field_2_first_col; return field_2_first_col;
@ -260,7 +229,6 @@ public final class RowRecord extends Record implements Comparable {
* get the logical col number for the last cell this row plus one (0 based index) * get the logical col number for the last cell this row plus one (0 based index)
* @return col - the last col number + 1 * @return col - the last col number + 1
*/ */
public short getLastCol() public short getLastCol()
{ {
return field_3_last_col; return field_3_last_col;
@ -270,7 +238,6 @@ public final class RowRecord extends Record implements Comparable {
* get the height of the row * get the height of the row
* @return height of the row * @return height of the row
*/ */
public short getHeight() public short getHeight()
{ {
return field_4_height; return field_4_height;
@ -280,7 +247,6 @@ public final class RowRecord extends Record implements Comparable {
* get whether to optimize or not (set to 0) * get whether to optimize or not (set to 0)
* @return optimize (set to 0) * @return optimize (set to 0)
*/ */
public short getOptimize() public short getOptimize()
{ {
return field_5_optimize; return field_5_optimize;
@ -291,7 +257,6 @@ public final class RowRecord extends Record implements Comparable {
* method) * method)
* @return options - the bitmask * @return options - the bitmask
*/ */
public short getOptionFlags() public short getOptionFlags()
{ {
return (short)field_7_option_flags; return (short)field_7_option_flags;
@ -304,7 +269,6 @@ public final class RowRecord extends Record implements Comparable {
* @return ol - the outline level * @return ol - the outline level
* @see #getOptionFlags() * @see #getOptionFlags()
*/ */
public short getOutlineLevel() public short getOutlineLevel()
{ {
return (short)outlineLevel.getValue(field_7_option_flags); return (short)outlineLevel.getValue(field_7_option_flags);
@ -315,7 +279,6 @@ public final class RowRecord extends Record implements Comparable {
* @return c - colapse or not * @return c - colapse or not
* @see #getOptionFlags() * @see #getOptionFlags()
*/ */
public boolean getColapsed() public boolean getColapsed()
{ {
return (colapsed.isSet(field_7_option_flags)); return (colapsed.isSet(field_7_option_flags));
@ -326,7 +289,6 @@ public final class RowRecord extends Record implements Comparable {
* @return - z height is zero or not. * @return - z height is zero or not.
* @see #getOptionFlags() * @see #getOptionFlags()
*/ */
public boolean getZeroHeight() public boolean getZeroHeight()
{ {
return zeroHeight.isSet(field_7_option_flags); return zeroHeight.isSet(field_7_option_flags);
@ -367,44 +329,27 @@ public final class RowRecord extends Record implements Comparable {
return field_8_xf_index; return field_8_xf_index;
} }
public boolean isInValueSection()
{
return true;
}
public String toString() public String toString()
{ {
StringBuffer buffer = new StringBuffer(); StringBuffer sb = new StringBuffer();
buffer.append("[ROW]\n"); sb.append("[ROW]\n");
buffer.append(" .rownumber = ") sb.append(" .rownumber = ").append(Integer.toHexString(getRowNumber()))
.append(Integer.toHexString(getRowNumber())).append("\n"); .append("\n");
buffer.append(" .firstcol = ") sb.append(" .firstcol = ").append(HexDump.shortToHex(getFirstCol())).append("\n");
.append(Integer.toHexString(getFirstCol())).append("\n"); sb.append(" .lastcol = ").append(HexDump.shortToHex(getLastCol())).append("\n");
buffer.append(" .lastcol = ") sb.append(" .height = ").append(HexDump.shortToHex(getHeight())).append("\n");
.append(Integer.toHexString(getLastCol())).append("\n"); sb.append(" .optimize = ").append(HexDump.shortToHex(getOptimize())).append("\n");
buffer.append(" .height = ") sb.append(" .reserved = ").append(HexDump.shortToHex(field_6_reserved)).append("\n");
.append(Integer.toHexString(getHeight())).append("\n"); sb.append(" .optionflags = ").append(HexDump.shortToHex(getOptionFlags())).append("\n");
buffer.append(" .optimize = ") sb.append(" .outlinelvl = ").append(Integer.toHexString(getOutlineLevel())).append("\n");
.append(Integer.toHexString(getOptimize())).append("\n"); sb.append(" .colapsed = ").append(getColapsed()).append("\n");
buffer.append(" .reserved = ") sb.append(" .zeroheight = ").append(getZeroHeight()).append("\n");
.append(Integer.toHexString(field_6_reserved)).append("\n"); sb.append(" .badfontheig= ").append(getBadFontHeight()).append("\n");
buffer.append(" .optionflags = ") sb.append(" .formatted = ").append(getFormatted()).append("\n");
.append(Integer.toHexString(getOptionFlags())).append("\n"); sb.append(" .xfindex = ").append(Integer.toHexString(getXFIndex())).append("\n");
buffer.append(" .outlinelvl = ") sb.append("[/ROW]\n");
.append(Integer.toHexString(getOutlineLevel())).append("\n"); return sb.toString();
buffer.append(" .colapsed = ").append(getColapsed())
.append("\n");
buffer.append(" .zeroheight = ").append(getZeroHeight())
.append("\n");
buffer.append(" .badfontheig= ").append(getBadFontHeight())
.append("\n");
buffer.append(" .formatted = ").append(getFormatted())
.append("\n");
buffer.append(" .xfindex = ")
.append(Integer.toHexString(getXFIndex())).append("\n");
buffer.append("[/ROW]\n");
return buffer.toString();
} }
public int serialize(int offset, byte [] data) public int serialize(int offset, byte [] data)
@ -433,40 +378,6 @@ public final class RowRecord extends Record implements Comparable {
return sid; return sid;
} }
public int compareTo(Object obj)
{
RowRecord loc = ( RowRecord ) obj;
if (this.getRowNumber() == loc.getRowNumber())
{
return 0;
}
if (this.getRowNumber() < loc.getRowNumber())
{
return -1;
}
if (this.getRowNumber() > loc.getRowNumber())
{
return 1;
}
return -1;
}
public boolean equals(Object obj)
{
if (!(obj instanceof RowRecord))
{
return false;
}
RowRecord loc = ( RowRecord ) obj;
if (this.getRowNumber() == loc.getRowNumber())
{
return true;
}
return false;
}
public Object clone() { public Object clone() {
RowRecord rec = new RowRecord(field_1_row_number); RowRecord rec = new RowRecord(field_1_row_number);
rec.field_2_first_col = field_2_first_col; rec.field_2_first_col = field_2_first_col;

View File

@ -115,20 +115,4 @@ public abstract class SharedValueRecordBase extends Record {
CellRangeAddress8Bit r = getRange(); CellRangeAddress8Bit r = getRange();
return r.getFirstRow() == rowIx && r.getFirstColumn() == colIx; return r.getFirstRow() == rowIx && r.getFirstColumn() == colIx;
} }
/**
* Mirroring formula records so it is registered in the
* ValueRecordsAggregate
*/
public final boolean isInValueSection() {
return true;
}
/**
* Register it in the ValueRecordsAggregate so it can go into the
* FormulaRecordAggregate
*/
public final boolean isValue() {
return true;
}
} }

View File

@ -1,4 +1,3 @@
/* ==================================================================== /* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with contributor license agreements. See the NOTICE file distributed with
@ -16,21 +15,18 @@
limitations under the License. limitations under the License.
==================================================================== */ ==================================================================== */
package org.apache.poi.hssf.record; package org.apache.poi.hssf.record;
import org.apache.poi.util.LittleEndian; import org.apache.poi.util.LittleEndian;
import org.apache.poi.util.StringUtil; import org.apache.poi.util.StringUtil;
/** /**
* Supports the STRING record structure. * Supports the STRING record structure. (0x0207)
* *
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public class StringRecord public class StringRecord extends Record {
extends Record public final static short sid = 0x0207;
{
public final static short sid = 0x207;
private int field_1_string_length; private int field_1_string_length;
private byte field_2_unicode_flag; private byte field_2_unicode_flag;
private String field_3_string; private String field_3_string;
@ -73,7 +69,7 @@ public class StringRecord
field_1_string_length = in.readShort(); field_1_string_length = in.readShort();
field_2_unicode_flag = in.readByte(); field_2_unicode_flag = in.readByte();
byte[] data = in.readRemainder(); byte[] data = in.readRemainder();
//Why isnt this using the in.readString methods??? //Why isn't this using the in.readString methods???
if (isUnCompressedUnicode()) if (isUnCompressedUnicode())
{ {
field_3_string = StringUtil.getFromUnicodeLE(data, 0, field_1_string_length ); field_3_string = StringUtil.getFromUnicodeLE(data, 0, field_1_string_length );
@ -92,11 +88,6 @@ public class StringRecord
} }
} }
public boolean isInValueSection()
{
return true;
}
private int getStringByteLength() private int getStringByteLength()
{ {
return isUnCompressedUnicode() ? field_1_string_length * 2 : field_1_string_length; return isUnCompressedUnicode() ? field_1_string_length * 2 : field_1_string_length;
@ -130,8 +121,8 @@ public class StringRecord
*/ */
public int serialize( int offset, byte[] data ) public int serialize( int offset, byte[] data )
{ {
LittleEndian.putShort(data, 0 + offset, sid); LittleEndian.putUShort(data, 0 + offset, sid);
LittleEndian.putShort(data, 2 + offset, ( short ) (3 + getStringByteLength())); LittleEndian.putUShort(data, 2 + offset, 3 + getStringByteLength());
LittleEndian.putUShort(data, 4 + offset, field_1_string_length); LittleEndian.putUShort(data, 4 + offset, field_1_string_length);
data[6 + offset] = field_2_unicode_flag; data[6 + offset] = field_2_unicode_flag;
if (isUnCompressedUnicode()) if (isUnCompressedUnicode())
@ -180,8 +171,6 @@ public class StringRecord
setCompressedFlag(StringUtil.hasMultibyte(string) ? (byte)1 : (byte)0); setCompressedFlag(StringUtil.hasMultibyte(string) ? (byte)1 : (byte)0);
} }
public String toString() public String toString()
{ {
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
@ -199,7 +188,5 @@ public class StringRecord
rec.field_2_unicode_flag= this.field_2_unicode_flag; rec.field_2_unicode_flag= this.field_2_unicode_flag;
rec.field_3_string = this.field_3_string; rec.field_3_string = this.field_3_string;
return rec; return rec;
} }
} }

View File

@ -24,7 +24,10 @@ import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.record.CFHeaderRecord; import org.apache.poi.hssf.record.CFHeaderRecord;
import org.apache.poi.hssf.record.CFRuleRecord; import org.apache.poi.hssf.record.CFRuleRecord;
import org.apache.poi.hssf.record.Record; import org.apache.poi.hssf.record.Record;
import org.apache.poi.ss.util.Region; import org.apache.poi.hssf.record.formula.AreaErrPtg;
import org.apache.poi.hssf.record.formula.AreaPtg;
import org.apache.poi.hssf.record.formula.FormulaShifter;
import org.apache.poi.hssf.record.formula.Ptg;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
/** /**
@ -175,4 +178,68 @@ public final class CFRecordsAggregate extends RecordAggregate {
rv.visitRecord(rule); rv.visitRecord(rule);
} }
} }
/**
* @return <code>false</code> if this whole {@link CFHeaderRecord} / {@link CFRuleRecord}s should be deleted
*/
public boolean updateFormulasAfterCellShift(FormulaShifter shifter, int currentExternSheetIx) {
CellRangeAddress[] cellRanges = header.getCellRanges();
boolean changed = false;
List temp = new ArrayList();
for (int i = 0; i < cellRanges.length; i++) {
CellRangeAddress craOld = cellRanges[i];
CellRangeAddress craNew = shiftRange(shifter, craOld, currentExternSheetIx);
if (craNew == null) {
changed = true;
continue;
}
temp.add(craNew);
if (craNew != craOld) {
changed = true;
}
}
if (changed) {
int nRanges = temp.size();
if (nRanges == 0) {
return false;
}
CellRangeAddress[] newRanges = new CellRangeAddress[nRanges];
temp.toArray(newRanges);
header.setCellRanges(newRanges);
}
for(int i=0; i<rules.size(); i++) {
CFRuleRecord rule = (CFRuleRecord)rules.get(i);
Ptg[] ptgs;
ptgs = rule.getParsedExpression1();
if (ptgs != null && shifter.adjustFormula(ptgs, currentExternSheetIx)) {
rule.setParsedExpression1(ptgs);
}
ptgs = rule.getParsedExpression2();
if (ptgs != null && shifter.adjustFormula(ptgs, currentExternSheetIx)) {
rule.setParsedExpression2(ptgs);
}
}
return true;
}
private static CellRangeAddress shiftRange(FormulaShifter shifter, CellRangeAddress cra, int currentExternSheetIx) {
// FormulaShifter works well in terms of Ptgs - so convert CellRangeAddress to AreaPtg (and back) here
AreaPtg aptg = new AreaPtg(cra.getFirstRow(), cra.getLastRow(), cra.getFirstColumn(), cra.getLastColumn(), false, false, false, false);
Ptg[] ptgs = { aptg, };
if (!shifter.adjustFormula(ptgs, currentExternSheetIx)) {
return cra;
}
Ptg ptg0 = ptgs[0];
if (ptg0 instanceof AreaPtg) {
AreaPtg bptg = (AreaPtg) ptg0;
return new CellRangeAddress(bptg.getFirstRow(), bptg.getLastRow(), bptg.getFirstColumn(), bptg.getLastColumn());
}
if (ptg0 instanceof AreaErrPtg) {
return null;
}
throw new IllegalStateException("Unexpected shifted ptg class (" + ptg0.getClass().getName() + ")");
}
} }

View File

@ -22,6 +22,7 @@ import java.util.List;
import org.apache.poi.hssf.model.RecordStream; import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.record.CFHeaderRecord; import org.apache.poi.hssf.record.CFHeaderRecord;
import org.apache.poi.hssf.record.formula.FormulaShifter;
/** /**
* Holds all the conditional formatting for a workbook sheet.<p/> * Holds all the conditional formatting for a workbook sheet.<p/>
@ -85,4 +86,15 @@ public final class ConditionalFormattingTable extends RecordAggregate {
+ " is outside the allowable range (0.." + (_cfHeaders.size() - 1) + ")"); + " is outside the allowable range (0.." + (_cfHeaders.size() - 1) + ")");
} }
} }
public void updateFormulasAfterCellShift(FormulaShifter shifter, int externSheetIndex) {
for (int i = 0; i < _cfHeaders.size(); i++) {
CFRecordsAggregate subAgg = (CFRecordsAggregate) _cfHeaders.get(i);
boolean shouldKeep = subAgg.updateFormulasAfterCellShift(shifter, externSheetIndex);
if (!shouldKeep) {
_cfHeaders.remove(i);
i--;
}
}
}
} }

View File

@ -47,11 +47,11 @@ public final class FormulaRecordAggregate extends RecordAggregate implements Cel
} }
boolean hasStringRec = stringRec != null; boolean hasStringRec = stringRec != null;
boolean hasCachedStringFlag = formulaRec.hasCachedResultString(); boolean hasCachedStringFlag = formulaRec.hasCachedResultString();
if (hasStringRec != hasCachedStringFlag) { if (hasStringRec != hasCachedStringFlag) {
throw new RecordFormatException("String record was " throw new RecordFormatException("String record was "
+ (hasStringRec ? "": "not ") + " supplied but formula record flag is " + (hasStringRec ? "": "not ") + " supplied but formula record flag is "
+ (hasCachedStringFlag ? "" : "not ") + " set"); + (hasCachedStringFlag ? "" : "not ") + " set");
} }
if (formulaRec.isSharedFormula()) { if (formulaRec.isSharedFormula()) {
svm.convertSharedFormulaRecord(formulaRec); svm.convertSharedFormulaRecord(formulaRec);

View File

@ -83,7 +83,7 @@ public final class RowRecordsAggregate extends RecordAggregate {
// might need to keep track of where exactly these belong // might need to keep track of where exactly these belong
continue; continue;
} }
if (!rec.isValue()) { if (!(rec instanceof CellValueRecordInterface)) {
throw new RuntimeException("Unexpected record type (" + rec.getClass().getName() + ")"); throw new RuntimeException("Unexpected record type (" + rec.getClass().getName() + ")");
} }
_valuesAgg.construct((CellValueRecordInterface)rec, rs, svm); _valuesAgg.construct((CellValueRecordInterface)rec, rs, svm);

View File

@ -1278,7 +1278,7 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet
int sheetIndex = workbook.getSheetIndex(this); int sheetIndex = workbook.getSheetIndex(this);
short externSheetIndex = book.checkExternSheet(sheetIndex); short externSheetIndex = book.checkExternSheet(sheetIndex);
FormulaShifter shifter = FormulaShifter.createForRowShift(externSheetIndex, startRow, endRow, n); FormulaShifter shifter = FormulaShifter.createForRowShift(externSheetIndex, startRow, endRow, n);
sheet.getRowsAggregate().updateFormulasAfterRowShift(shifter, externSheetIndex); sheet.updateFormulasAfterCellShift(shifter, externSheetIndex);
int nSheets = workbook.getNumberOfSheets(); int nSheets = workbook.getNumberOfSheets();
for(int i=0; i<nSheets; i++) { for(int i=0; i<nSheets; i++) {
@ -1287,7 +1287,7 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet
continue; continue;
} }
short otherExtSheetIx = book.checkExternSheet(i); short otherExtSheetIx = book.checkExternSheet(i);
otherSheet.getRowsAggregate().updateFormulasAfterRowShift(shifter, otherExtSheetIx); otherSheet.updateFormulasAfterCellShift(shifter, otherExtSheetIx);
} }
// TODO - adjust formulas in named ranges // TODO - adjust formulas in named ranges
} }

View File

@ -20,6 +20,7 @@ package org.apache.poi.hssf.usermodel;
import org.apache.poi.hssf.model.Sheet; import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.record.CFRuleRecord; import org.apache.poi.hssf.record.CFRuleRecord;
import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate; import org.apache.poi.hssf.record.aggregates.CFRecordsAggregate;
import org.apache.poi.hssf.record.aggregates.ConditionalFormattingTable;
import org.apache.poi.ss.util.Region; import org.apache.poi.ss.util.Region;
import org.apache.poi.ss.util.CellRangeAddress; import org.apache.poi.ss.util.CellRangeAddress;
@ -31,11 +32,11 @@ import org.apache.poi.ss.util.CellRangeAddress;
public final class HSSFSheetConditionalFormatting { public final class HSSFSheetConditionalFormatting {
private final HSSFWorkbook _workbook; private final HSSFWorkbook _workbook;
private final Sheet _sheet; private final ConditionalFormattingTable _conditionalFormattingTable;
/* package */ HSSFSheetConditionalFormatting(HSSFWorkbook workbook, Sheet sheet) { /* package */ HSSFSheetConditionalFormatting(HSSFWorkbook workbook, Sheet sheet) {
_workbook = workbook; _workbook = workbook;
_sheet = sheet; _conditionalFormattingTable = sheet.getConditionalFormattingTable();
} }
/** /**
@ -99,7 +100,7 @@ public final class HSSFSheetConditionalFormatting {
public int addConditionalFormatting( HSSFConditionalFormatting cf ) { public int addConditionalFormatting( HSSFConditionalFormatting cf ) {
CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate(); CFRecordsAggregate cfraClone = cf.getCFRecordsAggregate().cloneCFAggregate();
return _sheet.addConditionalFormatting(cfraClone); return _conditionalFormattingTable.add(cfraClone);
} }
/** /**
* @deprecated use <tt>CellRangeAddress</tt> instead of <tt>Region</tt> * @deprecated use <tt>CellRangeAddress</tt> instead of <tt>Region</tt>
@ -134,7 +135,7 @@ public final class HSSFSheetConditionalFormatting {
rules[i] = cfRules[i].getCfRuleRecord(); rules[i] = cfRules[i].getCfRuleRecord();
} }
CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules); CFRecordsAggregate cfra = new CFRecordsAggregate(regions, rules);
return _sheet.addConditionalFormatting(cfra); return _conditionalFormattingTable.add(cfra);
} }
public int addConditionalFormatting(CellRangeAddress[] regions, public int addConditionalFormatting(CellRangeAddress[] regions,
@ -166,7 +167,7 @@ public final class HSSFSheetConditionalFormatting {
* @return Conditional Formatting object * @return Conditional Formatting object
*/ */
public HSSFConditionalFormatting getConditionalFormattingAt(int index) { public HSSFConditionalFormatting getConditionalFormattingAt(int index) {
CFRecordsAggregate cf = _sheet.getCFRecordsAggregateAt(index); CFRecordsAggregate cf = _conditionalFormattingTable.get(index);
if (cf == null) { if (cf == null) {
return null; return null;
} }
@ -177,7 +178,7 @@ public final class HSSFSheetConditionalFormatting {
* @return number of Conditional Formatting objects of the sheet * @return number of Conditional Formatting objects of the sheet
*/ */
public int getNumConditionalFormattings() { public int getNumConditionalFormattings() {
return _sheet.getNumConditionalFormattings(); return _conditionalFormattingTable.size();
} }
/** /**
@ -185,6 +186,6 @@ public final class HSSFSheetConditionalFormatting {
* @param index of a Conditional Formatting object to remove * @param index of a Conditional Formatting object to remove
*/ */
public void removeConditionalFormatting(int index) { public void removeConditionalFormatting(int index) {
_sheet.removeConditionalFormatting(index); _conditionalFormattingTable.remove(index);
} }
} }

View File

@ -33,6 +33,7 @@ import org.apache.poi.ddf.EscherBSERecord;
import org.apache.poi.ddf.EscherBitmapBlip; import org.apache.poi.ddf.EscherBitmapBlip;
import org.apache.poi.ddf.EscherBlipRecord; import org.apache.poi.ddf.EscherBlipRecord;
import org.apache.poi.ddf.EscherRecord; import org.apache.poi.ddf.EscherRecord;
import org.apache.poi.hssf.model.RecordStream;
import org.apache.poi.hssf.model.Sheet; import org.apache.poi.hssf.model.Sheet;
import org.apache.poi.hssf.model.Workbook; import org.apache.poi.hssf.model.Workbook;
import org.apache.poi.hssf.record.AbstractEscherHolderRecord; import org.apache.poi.hssf.record.AbstractEscherHolderRecord;
@ -277,10 +278,9 @@ public class HSSFWorkbook extends POIDocument implements org.apache.poi.ss.userm
// convert all LabelRecord records to LabelSSTRecord // convert all LabelRecord records to LabelSSTRecord
convertLabelRecords(records, recOffset); convertLabelRecords(records, recOffset);
while (recOffset < records.size()) { RecordStream rs = new RecordStream(records, recOffset);
Sheet sheet = Sheet.createSheet(records, sheetNum++, recOffset ); while (rs.hasNext()) {
Sheet sheet = Sheet.createSheet(rs);
recOffset = sheet.getEofLoc()+1; // TODO - use better technique to keep track of the used records
_sheets.add(new HSSFSheet(this, sheet)); _sheets.add(new HSSFSheet(this, sheet));
} }

View File

@ -56,6 +56,11 @@ import org.apache.poi.hssf.util.CellRangeAddress;
* @author Glen Stampoultzis (glens at apache.org) * @author Glen Stampoultzis (glens at apache.org)
*/ */
public final class TestSheet extends TestCase { public final class TestSheet extends TestCase {
private static Sheet createSheet(List inRecs) {
return Sheet.createSheet(new RecordStream(inRecs, 0));
}
public void testCreateSheet() { public void testCreateSheet() {
// Check we're adding row and cell aggregates // Check we're adding row and cell aggregates
List records = new ArrayList(); List records = new ArrayList();
@ -63,7 +68,7 @@ public final class TestSheet extends TestCase {
records.add( new DimensionsRecord() ); records.add( new DimensionsRecord() );
records.add(createWindow2Record()); records.add(createWindow2Record());
records.add(EOFRecord.instance); records.add(EOFRecord.instance);
Sheet sheet = Sheet.createSheet( records, 0, 0 ); Sheet sheet = createSheet(records);
int pos = 0; int pos = 0;
assertTrue( sheet.records.get(pos++) instanceof BOFRecord ); assertTrue( sheet.records.get(pos++) instanceof BOFRecord );
@ -187,7 +192,7 @@ public final class TestSheet extends TestCase {
records.add(EOFRecord.instance); records.add(EOFRecord.instance);
records.add(merged); records.add(merged);
Sheet sheet = Sheet.createSheet(records, 0); Sheet sheet = createSheet(records);
sheet.records.remove(0); sheet.records.remove(0);
//stub object to throw off list INDEX operations //stub object to throw off list INDEX operations
@ -222,7 +227,7 @@ public final class TestSheet extends TestCase {
records.add(createWindow2Record()); records.add(createWindow2Record());
records.add(EOFRecord.instance); records.add(EOFRecord.instance);
Sheet sheet = Sheet.createSheet(records, 0); Sheet sheet = createSheet(records);
assertNotNull("Row [2] was skipped", sheet.getRow(2)); assertNotNull("Row [2] was skipped", sheet.getRow(2));
} }
@ -446,7 +451,7 @@ public final class TestSheet extends TestCase {
records.add(new DimensionsRecord()); records.add(new DimensionsRecord());
records.add(createWindow2Record()); records.add(createWindow2Record());
records.add(EOFRecord.instance); records.add(EOFRecord.instance);
Sheet sheet = Sheet.createSheet(records, 0, 0); Sheet sheet = createSheet(records);
// The original bug was due to different logic for collecting records for sizing and // The original bug was due to different logic for collecting records for sizing and
// serialization. The code has since been refactored into a single method for visiting // serialization. The code has since been refactored into a single method for visiting

View File

@ -82,11 +82,9 @@ public final class TestExternalNameRecord extends TestCase {
assertTrue(enr.isAutomaticLink()); assertTrue(enr.isAutomaticLink());
assertFalse(enr.isBuiltInName()); assertFalse(enr.isBuiltInName());
assertFalse(enr.isIconifiedPictureLink()); assertFalse(enr.isIconifiedPictureLink());
assertFalse(enr.isInValueSection());
assertFalse(enr.isOLELink()); assertFalse(enr.isOLELink());
assertFalse(enr.isPicureLink()); assertFalse(enr.isPicureLink());
assertTrue(enr.isStdDocumentNameIdentifier()); assertTrue(enr.isStdDocumentNameIdentifier());
assertFalse(enr.isValue());
TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataAutoDocName, enr.serialize()); TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataAutoDocName, enr.serialize());
} }
@ -98,11 +96,9 @@ public final class TestExternalNameRecord extends TestCase {
assertFalse(enr.isAutomaticLink()); assertFalse(enr.isAutomaticLink());
assertFalse(enr.isBuiltInName()); assertFalse(enr.isBuiltInName());
assertFalse(enr.isIconifiedPictureLink()); assertFalse(enr.isIconifiedPictureLink());
assertFalse(enr.isInValueSection());
assertFalse(enr.isOLELink()); assertFalse(enr.isOLELink());
assertFalse(enr.isPicureLink()); assertFalse(enr.isPicureLink());
assertFalse(enr.isStdDocumentNameIdentifier()); assertFalse(enr.isStdDocumentNameIdentifier());
assertFalse(enr.isValue());
TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataPlainName, enr.serialize()); TestcaseRecordInputStream.confirmRecordEncoding(0x0023, dataPlainName, enr.serialize());
} }

View File

@ -65,7 +65,7 @@ public final class TestValueRecordsAggregate extends TestCase {
} }
private void constructValueRecord(List records) { private void constructValueRecord(List records) {
RowBlocksReader rbr = new RowBlocksReader(records, 0); RowBlocksReader rbr = new RowBlocksReader(new RecordStream(records, 0));
SharedValueManager sfrh = rbr.getSharedFormulaManager(); SharedValueManager sfrh = rbr.getSharedFormulaManager();
RecordStream rs = rbr.getPlainRecordStream(); RecordStream rs = rbr.getPlainRecordStream();
while(rs.hasNext()) { while(rs.hasNext()) {

View File

@ -29,10 +29,8 @@ import org.apache.poi.ss.util.Region;
* *
* @author Dmitriy Kumshayev * @author Dmitriy Kumshayev
*/ */
public final class TestHSSFConditionalFormatting extends TestCase public final class TestHSSFConditionalFormatting extends TestCase {
{ public void testCreateCF() {
public void testCreateCF()
{
HSSFWorkbook workbook = new HSSFWorkbook(); HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet(); HSSFSheet sheet = workbook.createSheet();
String formula = "7"; String formula = "7";
@ -150,4 +148,44 @@ public final class TestHSSFConditionalFormatting extends TestCase
} }
assertEquals(2, wb.getNumberOfSheets()); assertEquals(2, wb.getNumberOfSheets());
} }
public void testShiftRows() {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet();
HSSFSheetConditionalFormatting sheetCF = sheet.getSheetConditionalFormatting();
HSSFConditionalFormattingRule rule1 = sheetCF.createConditionalFormattingRule(
ComparisonOperator.BETWEEN, "sum(A10:A15)", "1+sum(B16:B30)");
HSSFFontFormatting fontFmt = rule1.createFontFormatting();
fontFmt.setFontStyle(true, false);
HSSFPatternFormatting patternFmt = rule1.createPatternFormatting();
patternFmt.setFillBackgroundColor(HSSFColor.YELLOW.index);
HSSFConditionalFormattingRule [] cfRules = { rule1, };
CellRangeAddress [] regions = {
new CellRangeAddress(2, 4, 0, 0), // A3:A5
};
sheetCF.addConditionalFormatting(regions, cfRules);
// This row-shift should destroy the CF region
sheet.shiftRows(10, 20, -9);
assertEquals(0, sheetCF.getNumConditionalFormattings());
// re-add the CF
sheetCF.addConditionalFormatting(regions, cfRules);
// This row shift should only affect the formulas
sheet.shiftRows(14, 17, 8);
HSSFConditionalFormatting cf = sheetCF.getConditionalFormattingAt(0);
assertEquals("SUM(A10:A23)", cf.getRule(0).getFormula1());
assertEquals("1+SUM(B24:B30)", cf.getRule(0).getFormula2());
sheet.shiftRows(0, 8, 21);
cf = sheetCF.getConditionalFormattingAt(0);
assertEquals("SUM(A10:A21)", cf.getRule(0).getFormula1());
assertEquals("1+SUM(#REF!)", cf.getRule(0).getFormula2());
}
} }