use of org.apache.poi.hssf.record.aggregates.RecordAggregate in project poi by apache.
the class InternalSheet method visitContainedRecords.
public void visitContainedRecords(RecordVisitor rv, int offset) {
PositionTrackingVisitor ptv = new PositionTrackingVisitor(rv, offset);
boolean haveSerializedIndex = false;
for (int k = 0; k < _records.size(); k++) {
RecordBase record = _records.get(k);
if (record instanceof RecordAggregate) {
RecordAggregate agg = (RecordAggregate) record;
agg.visitContainedRecords(ptv);
} else {
ptv.visitRecord((Record) record);
}
// If the BOF record was just serialized then add the IndexRecord
if (record instanceof BOFRecord) {
if (!haveSerializedIndex) {
haveSerializedIndex = true;
// and one shouldn't go in after that!
if (_isUncalced) {
ptv.visitRecord(new UncalcedRecord());
}
//remove this guard. So be safe it is left here.
if (_rowsAggregate != null) {
// find forward distance to first RowRecord
int initRecsSize = getSizeOfInitialSheetRecords(k);
int currentPos = ptv.getPosition();
ptv.visitRecord(_rowsAggregate.createIndexRecord(currentPos, initRecsSize));
}
}
}
}
}
use of org.apache.poi.hssf.record.aggregates.RecordAggregate in project poi by apache.
the class InternalSheet method cloneSheet.
/**
* Clones the low level records of this sheet and returns the new sheet instance.
* This method is implemented by adding methods for deep cloning to all records that
* can be added to a sheet. The <b>Record</b> object does not implement cloneable.
* When adding a new record, implement a public clone method if and only if the record
* belongs to a sheet.
*
* @return the cloned sheet
*/
public InternalSheet cloneSheet() {
List<Record> clonedRecords = new ArrayList<Record>(_records.size());
for (int i = 0; i < _records.size(); i++) {
RecordBase rb = _records.get(i);
if (rb instanceof RecordAggregate) {
((RecordAggregate) rb).visitContainedRecords(new RecordCloner(clonedRecords));
continue;
}
if (rb instanceof EscherAggregate) {
/**
* this record will be removed after reading actual data from EscherAggregate
*/
rb = new DrawingRecord();
}
try {
Record rec = (Record) ((Record) rb).clone();
clonedRecords.add(rec);
} catch (CloneNotSupportedException e) {
throw new RecordFormatException(e);
}
}
return createSheet(new RecordStream(clonedRecords, 0));
}
Aggregations