Search in sources :

Example 16 with RecordBase

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()]);
}
Also used : LegendRecord(org.apache.poi.hssf.record.chart.LegendRecord) SeriesTextRecord(org.apache.poi.hssf.record.chart.SeriesTextRecord) ArrayList(java.util.ArrayList) ChartRecord(org.apache.poi.hssf.record.chart.ChartRecord) SeriesRecord(org.apache.poi.hssf.record.chart.SeriesRecord) ChartTitleFormatRecord(org.apache.poi.hssf.record.chart.ChartTitleFormatRecord) RecordBase(org.apache.poi.hssf.record.RecordBase) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) VCenterRecord(org.apache.poi.hssf.record.VCenterRecord) AxisUsedRecord(org.apache.poi.hssf.record.chart.AxisUsedRecord) LinkedDataRecord(org.apache.poi.hssf.record.chart.LinkedDataRecord) FooterRecord(org.apache.poi.hssf.record.FooterRecord) SCLRecord(org.apache.poi.hssf.record.SCLRecord) ChartRecord(org.apache.poi.hssf.record.chart.ChartRecord) ValueRangeRecord(org.apache.poi.hssf.record.chart.ValueRangeRecord) LegendRecord(org.apache.poi.hssf.record.chart.LegendRecord) SeriesTextRecord(org.apache.poi.hssf.record.chart.SeriesTextRecord) AxisParentRecord(org.apache.poi.hssf.record.chart.AxisParentRecord) DefaultDataLabelTextPropertiesRecord(org.apache.poi.hssf.record.chart.DefaultDataLabelTextPropertiesRecord) PrintSetupRecord(org.apache.poi.hssf.record.PrintSetupRecord) Record(org.apache.poi.hssf.record.Record) SeriesToChartGroupRecord(org.apache.poi.hssf.record.chart.SeriesToChartGroupRecord) EOFRecord(org.apache.poi.hssf.record.EOFRecord) AreaFormatRecord(org.apache.poi.hssf.record.chart.AreaFormatRecord) BeginRecord(org.apache.poi.hssf.record.chart.BeginRecord) HCenterRecord(org.apache.poi.hssf.record.HCenterRecord) EndRecord(org.apache.poi.hssf.record.chart.EndRecord) PlotGrowthRecord(org.apache.poi.hssf.record.chart.PlotGrowthRecord) UnitsRecord(org.apache.poi.hssf.record.chart.UnitsRecord) HeaderRecord(org.apache.poi.hssf.record.HeaderRecord) SeriesRecord(org.apache.poi.hssf.record.chart.SeriesRecord) BarRecord(org.apache.poi.hssf.record.chart.BarRecord) ChartFormatRecord(org.apache.poi.hssf.record.chart.ChartFormatRecord) AxisLineFormatRecord(org.apache.poi.hssf.record.chart.AxisLineFormatRecord) CategorySeriesAxisRecord(org.apache.poi.hssf.record.chart.CategorySeriesAxisRecord) ChartTitleFormatRecord(org.apache.poi.hssf.record.chart.ChartTitleFormatRecord) FrameRecord(org.apache.poi.hssf.record.chart.FrameRecord) PlotAreaRecord(org.apache.poi.hssf.record.chart.PlotAreaRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) DataFormatRecord(org.apache.poi.hssf.record.chart.DataFormatRecord) ProtectRecord(org.apache.poi.hssf.record.ProtectRecord) TextRecord(org.apache.poi.hssf.record.chart.TextRecord) FontBasisRecord(org.apache.poi.hssf.record.chart.FontBasisRecord) AxisOptionsRecord(org.apache.poi.hssf.record.chart.AxisOptionsRecord) SeriesIndexRecord(org.apache.poi.hssf.record.chart.SeriesIndexRecord) SheetPropertiesRecord(org.apache.poi.hssf.record.chart.SheetPropertiesRecord) TickRecord(org.apache.poi.hssf.record.chart.TickRecord) AxisRecord(org.apache.poi.hssf.record.chart.AxisRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) FontIndexRecord(org.apache.poi.hssf.record.chart.FontIndexRecord) LineFormatRecord(org.apache.poi.hssf.record.chart.LineFormatRecord) LinkedDataRecord(org.apache.poi.hssf.record.chart.LinkedDataRecord) ValueRangeRecord(org.apache.poi.hssf.record.chart.ValueRangeRecord)

Example 17 with RecordBase

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));
                }
            }
        }
    }
}
Also used : PositionTrackingVisitor(org.apache.poi.hssf.record.aggregates.RecordAggregate.PositionTrackingVisitor) UncalcedRecord(org.apache.poi.hssf.record.UncalcedRecord) RecordBase(org.apache.poi.hssf.record.RecordBase) CustomViewSettingsRecordAggregate(org.apache.poi.hssf.record.aggregates.CustomViewSettingsRecordAggregate) RecordAggregate(org.apache.poi.hssf.record.aggregates.RecordAggregate) ChartSubstreamRecordAggregate(org.apache.poi.hssf.record.aggregates.ChartSubstreamRecordAggregate) BOFRecord(org.apache.poi.hssf.record.BOFRecord)

Example 18 with RecordBase

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");
}
Also used : RecordBase(org.apache.poi.hssf.record.RecordBase)

Example 19 with RecordBase

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));
}
Also used : EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) RecordFormatException(org.apache.poi.hssf.record.RecordFormatException) RecordBase(org.apache.poi.hssf.record.RecordBase) ArrayList(java.util.ArrayList) GutsRecord(org.apache.poi.hssf.record.GutsRecord) MergeCellsRecord(org.apache.poi.hssf.record.MergeCellsRecord) DefaultColWidthRecord(org.apache.poi.hssf.record.DefaultColWidthRecord) DefaultRowHeightRecord(org.apache.poi.hssf.record.DefaultRowHeightRecord) GridsetRecord(org.apache.poi.hssf.record.GridsetRecord) SCLRecord(org.apache.poi.hssf.record.SCLRecord) DrawingRecord(org.apache.poi.hssf.record.DrawingRecord) NoteRecord(org.apache.poi.hssf.record.NoteRecord) CFHeaderRecord(org.apache.poi.hssf.record.CFHeaderRecord) Record(org.apache.poi.hssf.record.Record) EOFRecord(org.apache.poi.hssf.record.EOFRecord) PrintHeadersRecord(org.apache.poi.hssf.record.PrintHeadersRecord) RefModeRecord(org.apache.poi.hssf.record.RefModeRecord) RowRecord(org.apache.poi.hssf.record.RowRecord) CalcCountRecord(org.apache.poi.hssf.record.CalcCountRecord) ColumnInfoRecord(org.apache.poi.hssf.record.ColumnInfoRecord) WindowTwoRecord(org.apache.poi.hssf.record.WindowTwoRecord) PrintGridlinesRecord(org.apache.poi.hssf.record.PrintGridlinesRecord) IterationRecord(org.apache.poi.hssf.record.IterationRecord) FeatHdrRecord(org.apache.poi.hssf.record.FeatHdrRecord) CalcModeRecord(org.apache.poi.hssf.record.CalcModeRecord) SelectionRecord(org.apache.poi.hssf.record.SelectionRecord) IndexRecord(org.apache.poi.hssf.record.IndexRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) DVALRecord(org.apache.poi.hssf.record.DVALRecord) DeltaRecord(org.apache.poi.hssf.record.DeltaRecord) PaneRecord(org.apache.poi.hssf.record.PaneRecord) FeatRecord(org.apache.poi.hssf.record.FeatRecord) WSBoolRecord(org.apache.poi.hssf.record.WSBoolRecord) SaveRecalcRecord(org.apache.poi.hssf.record.SaveRecalcRecord) CFHeader12Record(org.apache.poi.hssf.record.CFHeader12Record) UncalcedRecord(org.apache.poi.hssf.record.UncalcedRecord) DimensionsRecord(org.apache.poi.hssf.record.DimensionsRecord) CustomViewSettingsRecordAggregate(org.apache.poi.hssf.record.aggregates.CustomViewSettingsRecordAggregate) RecordAggregate(org.apache.poi.hssf.record.aggregates.RecordAggregate) ChartSubstreamRecordAggregate(org.apache.poi.hssf.record.aggregates.ChartSubstreamRecordAggregate) DrawingRecord(org.apache.poi.hssf.record.DrawingRecord)

Example 20 with RecordBase

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;
}
Also used : EscherAggregate(org.apache.poi.hssf.record.EscherAggregate) RecordBase(org.apache.poi.hssf.record.RecordBase)

Aggregations

RecordBase (org.apache.poi.hssf.record.RecordBase)29 Test (org.junit.Test)14 EOFRecord (org.apache.poi.hssf.record.EOFRecord)12 EscherAggregate (org.apache.poi.hssf.record.EscherAggregate)12 Record (org.apache.poi.hssf.record.Record)12 DrawingRecord (org.apache.poi.hssf.record.DrawingRecord)9 NoteRecord (org.apache.poi.hssf.record.NoteRecord)9 WindowTwoRecord (org.apache.poi.hssf.record.WindowTwoRecord)9 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)9 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)8 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)8 ObjRecord (org.apache.poi.hssf.record.ObjRecord)8 TextObjectRecord (org.apache.poi.hssf.record.TextObjectRecord)8 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)8 EscherRecord (org.apache.poi.ddf.EscherRecord)7 ContinueRecord (org.apache.poi.hssf.record.ContinueRecord)7 BOFRecord (org.apache.poi.hssf.record.BOFRecord)6 ArrayList (java.util.ArrayList)5 RowRecordsAggregate (org.apache.poi.hssf.record.aggregates.RowRecordsAggregate)5 DimensionsRecord (org.apache.poi.hssf.record.DimensionsRecord)4