use of org.apache.poi.hssf.record.RecordBase in project poi by apache.
the class HSSFChart method getSheetCharts.
/**
* Returns all the charts for the given sheet.
*
* NOTE: You won't be able to do very much with
* these charts yet, as this is very limited support
*/
public static HSSFChart[] getSheetCharts(HSSFSheet sheet) {
List<HSSFChart> charts = new ArrayList<HSSFChart>();
HSSFChart lastChart = null;
HSSFSeries lastSeries = null;
// Find records of interest
List<RecordBase> records = sheet.getSheet().getRecords();
for (RecordBase r : records) {
if (r instanceof ChartRecord) {
lastSeries = null;
lastChart = new HSSFChart(sheet, (ChartRecord) r);
charts.add(lastChart);
} else if (r instanceof LinkedDataRecord) {
LinkedDataRecord linkedDataRecord = (LinkedDataRecord) r;
if (lastSeries != null) {
lastSeries.insertData(linkedDataRecord);
}
}
if (lastChart == null) {
continue;
}
if (r instanceof LegendRecord) {
lastChart.legendRecord = (LegendRecord) r;
} else if (r instanceof SeriesRecord) {
HSSFSeries series = new HSSFSeries((SeriesRecord) r);
lastChart.series.add(series);
lastSeries = series;
} else if (r instanceof ChartTitleFormatRecord) {
lastChart.chartTitleFormat = (ChartTitleFormatRecord) r;
} else if (r instanceof SeriesTextRecord) {
// Applies to a series, unless we've seen a legend already
SeriesTextRecord str = (SeriesTextRecord) r;
if (lastChart.legendRecord == null && lastChart.series.size() > 0) {
HSSFSeries series = lastChart.series.get(lastChart.series.size() - 1);
series.seriesTitleText = str;
} else {
lastChart.chartTitleText = str;
}
} else if (r instanceof ValueRangeRecord) {
lastChart.valueRanges.add((ValueRangeRecord) r);
} else if (r instanceof Record) {
Record record = (Record) r;
for (HSSFChartType type : HSSFChartType.values()) {
if (type == HSSFChartType.Unknown) {
continue;
}
if (record.getSid() == type.getSid()) {
lastChart.type = type;
break;
}
}
}
}
return charts.toArray(new HSSFChart[charts.size()]);
}
use of org.apache.poi.hssf.record.RecordBase 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.RecordBase in project poi by apache.
the class RecordOrderer method getGutsRecordInsertPos.
private static int getGutsRecordInsertPos(List<RecordBase> records) {
int dimensionsIndex = getDimensionsIndex(records);
int i = dimensionsIndex - 1;
while (i > 0) {
i--;
RecordBase rb = records.get(i);
if (isGutsPriorRecord(rb)) {
return i + 1;
}
}
throw new RuntimeException("Did not find insert point for GUTS");
}
use of org.apache.poi.hssf.record.RecordBase 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));
}
use of org.apache.poi.hssf.record.RecordBase in project poi by apache.
the class InternalSheet method aggregateDrawingRecords.
/**
* Finds the DrawingRecord for our sheet, and
* attaches it to the DrawingManager (which knows about
* the overall DrawingGroup for our workbook).
* If requested, will create a new DrawRecord
* if none currently exist
* @param drawingManager The DrawingManager2 for our workbook
* @param createIfMissing Should one be created if missing?
* @return location of EscherAggregate record. if no EscherAggregate record is found return -1
*/
public int aggregateDrawingRecords(DrawingManager2 drawingManager, boolean createIfMissing) {
int loc = findFirstRecordLocBySid(DrawingRecord.sid);
boolean noDrawingRecordsFound = (loc == -1);
if (noDrawingRecordsFound) {
if (!createIfMissing) {
// None found, and not allowed to add in
return -1;
}
EscherAggregate aggregate = new EscherAggregate(true);
loc = findFirstRecordLocBySid(EscherAggregate.sid);
if (loc == -1) {
loc = findFirstRecordLocBySid(WindowTwoRecord.sid);
} else {
getRecords().remove(loc);
}
getRecords().add(loc, aggregate);
return loc;
}
List<RecordBase> records = getRecords();
EscherAggregate.createAggregate(records, loc);
return loc;
}
Aggregations