Search in sources :

Example 46 with Record

use of org.apache.poi.hssf.record.Record in project poi by apache.

the class RecordsStresser method handleWorkbook.

public static void handleWorkbook(HSSFWorkbook wb) {
    List<Record> records = wb.getWorkbook().getRecords();
    for (Record record : records) {
        //            }
        try {
            Record newRecord = (Record) record.clone();
            assertEquals("Expecting the same class back from clone(), but had Record of type " + record.getClass() + " and got back a " + newRecord.getClass() + " from clone()", record.getClass(), newRecord.getClass());
            byte[] origBytes = record.serialize();
            byte[] newBytes = newRecord.serialize();
            assertArrayEquals("Record of type " + record.getClass() + " should return the same byte array via the clone() method, but did return a different array", origBytes, newBytes);
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        } catch (RuntimeException e) {
            // some Records do not implement clone, ignore those for now
            assertTrue(e.getMessage().contains("needs to define a clone method"));
        }
    }
}
Also used : Record(org.apache.poi.hssf.record.Record)

Example 47 with Record

use of org.apache.poi.hssf.record.Record in project poi by apache.

the class FormulaRecordAggregate method visitContainedRecords.

public void visitContainedRecords(RecordVisitor rv) {
    rv.visitRecord(_formulaRecord);
    Record sharedFormulaRecord = _sharedValueManager.getRecordForFirstCell(this);
    if (sharedFormulaRecord != null) {
        rv.visitRecord(sharedFormulaRecord);
    }
    if (_formulaRecord.hasCachedResultString() && _stringRecord != null) {
        rv.visitRecord(_stringRecord);
    }
}
Also used : Record(org.apache.poi.hssf.record.Record) StringRecord(org.apache.poi.hssf.record.StringRecord) ArrayRecord(org.apache.poi.hssf.record.ArrayRecord) SharedFormulaRecord(org.apache.poi.hssf.record.SharedFormulaRecord) FormulaRecord(org.apache.poi.hssf.record.FormulaRecord)

Example 48 with Record

use of org.apache.poi.hssf.record.Record in project poi by apache.

the class TestBugs method bug46664.

/**
     * Newly created sheets need to get a
     *  proper TabID, otherwise print setup
     *  gets confused on them.
     * Also ensure that print setup refs are
     *  by reference not value
     */
@Test
public void bug46664() throws Exception {
    HSSFWorkbook wb1 = new HSSFWorkbook();
    HSSFSheet sheet = wb1.createSheet("new_sheet");
    HSSFRow row = sheet.createRow((short) 0);
    row.createCell(0).setCellValue(new HSSFRichTextString("Column A"));
    row.createCell(1).setCellValue(new HSSFRichTextString("Column B"));
    row.createCell(2).setCellValue(new HSSFRichTextString("Column C"));
    row.createCell(3).setCellValue(new HSSFRichTextString("Column D"));
    row.createCell(4).setCellValue(new HSSFRichTextString("Column E"));
    row.createCell(5).setCellValue(new HSSFRichTextString("Column F"));
    //set print area from column a to column c (on first row)
    wb1.setPrintArea(//sheet index
    0, //start column
    0, //end column
    2, //start row
    0, //end row
    0);
    HSSFWorkbook wb2 = writeOutAndReadBack(wb1);
    wb1.close();
    // Ensure the tab index
    TabIdRecord tr = null;
    for (Record r : wb2.getWorkbook().getRecords()) {
        if (r instanceof TabIdRecord) {
            tr = (TabIdRecord) r;
        }
    }
    assertNotNull(tr);
    assertEquals(1, tr._tabids.length);
    assertEquals(0, tr._tabids[0]);
    // Ensure the print setup
    assertEquals("new_sheet!$A$1:$C$1", wb2.getPrintArea(0));
    HSSFName printArea = wb2.getName("Print_Area");
    assertNotNull(printArea);
    assertEquals("new_sheet!$A$1:$C$1", printArea.getRefersToFormula());
    // Needs reference not value
    NameRecord nr = wb2.getWorkbook().getNameRecord(wb2.getNameIndex("Print_Area"));
    assertEquals("Print_Area", nr.getNameText());
    assertEquals(1, nr.getNameDefinition().length);
    assertEquals("new_sheet!$A$1:$C$1", ((Area3DPtg) nr.getNameDefinition()[0]).toFormulaString(HSSFEvaluationWorkbook.create(wb2)));
    assertEquals('R', nr.getNameDefinition()[0].getRVAType());
    wb2.close();
}
Also used : TabIdRecord(org.apache.poi.hssf.record.TabIdRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) UnknownRecord(org.apache.poi.hssf.record.UnknownRecord) Record(org.apache.poi.hssf.record.Record) EmbeddedObjectRefSubRecord(org.apache.poi.hssf.record.EmbeddedObjectRefSubRecord) CommonObjectDataSubRecord(org.apache.poi.hssf.record.CommonObjectDataSubRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) TabIdRecord(org.apache.poi.hssf.record.TabIdRecord) Test(org.junit.Test)

Example 49 with Record

use of org.apache.poi.hssf.record.Record in project poi by apache.

the class HSSFChart method createBarChart.

/**
	 * Creates a bar chart.  API needs some work. :)
	 * <p>
	 * NOTE:  Does not yet work...  checking it in just so others
	 * can take a look.
	 */
public void createBarChart(HSSFWorkbook workbook, HSSFSheet parentSheet) {
    List<Record> records = new ArrayList<Record>();
    records.add(createMSDrawingObjectRecord());
    records.add(createOBJRecord());
    records.add(createBOFRecord());
    records.add(new HeaderRecord(""));
    records.add(new FooterRecord(""));
    records.add(createHCenterRecord());
    records.add(createVCenterRecord());
    records.add(createPrintSetupRecord());
    // unknown 33
    records.add(createFontBasisRecord1());
    records.add(createFontBasisRecord2());
    records.add(new ProtectRecord(false));
    records.add(createUnitsRecord());
    records.add(createChartRecord(0, 0, 30434904, 19031616));
    records.add(createBeginRecord());
    records.add(createSCLRecord((short) 1, (short) 1));
    records.add(createPlotGrowthRecord(65536, 65536));
    records.add(createFrameRecord1());
    records.add(createBeginRecord());
    records.add(createLineFormatRecord(true));
    records.add(createAreaFormatRecord1());
    records.add(createEndRecord());
    records.add(createSeriesRecord());
    records.add(createBeginRecord());
    records.add(createTitleLinkedDataRecord());
    records.add(createValuesLinkedDataRecord());
    records.add(createCategoriesLinkedDataRecord());
    records.add(createDataFormatRecord());
    //		records.add(createBeginRecord());
    // unknown
    //		records.add(createEndRecord());
    records.add(createSeriesToChartGroupRecord());
    records.add(createEndRecord());
    records.add(createSheetPropsRecord());
    records.add(createDefaultTextRecord(DefaultDataLabelTextPropertiesRecord.CATEGORY_DATA_TYPE_ALL_TEXT_CHARACTERISTIC));
    records.add(createAllTextRecord());
    records.add(createBeginRecord());
    // unknown
    records.add(createFontIndexRecord(5));
    records.add(createDirectLinkRecord());
    records.add(createEndRecord());
    // eek, undocumented text type
    records.add(createDefaultTextRecord((short) 3));
    records.add(createUnknownTextRecord());
    records.add(createBeginRecord());
    records.add(createFontIndexRecord((short) 6));
    records.add(createDirectLinkRecord());
    records.add(createEndRecord());
    records.add(createAxisUsedRecord((short) 1));
    createAxisRecords(records);
    records.add(createEndRecord());
    records.add(createDimensionsRecord());
    records.add(createSeriesIndexRecord(2));
    records.add(createSeriesIndexRecord(1));
    records.add(createSeriesIndexRecord(3));
    records.add(EOFRecord.instance);
    parentSheet.insertChartRecords(records);
    workbook.insertChartRecord();
}
Also used : ProtectRecord(org.apache.poi.hssf.record.ProtectRecord) FooterRecord(org.apache.poi.hssf.record.FooterRecord) HeaderRecord(org.apache.poi.hssf.record.HeaderRecord) ArrayList(java.util.ArrayList) 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)

Example 50 with Record

use of org.apache.poi.hssf.record.Record in project poi by apache.

the class HSSFChart method createSeries.

public HSSFSeries createSeries() throws Exception {
    ArrayList<RecordBase> seriesTemplate = new ArrayList<RecordBase>();
    boolean seriesTemplateFilled = false;
    int idx = 0;
    int deep = 0;
    int chartRecordIdx = -1;
    int chartDeep = -1;
    int lastSeriesDeep = -1;
    int endSeriesRecordIdx = -1;
    int seriesIdx = 0;
    final List<RecordBase> records = sheet.getSheet().getRecords();
    /* store first series as template and find last series index */
    for (final RecordBase record : records) {
        idx++;
        if (record instanceof BeginRecord) {
            deep++;
        } else if (record instanceof EndRecord) {
            deep--;
            if (lastSeriesDeep == deep) {
                lastSeriesDeep = -1;
                endSeriesRecordIdx = idx;
                if (!seriesTemplateFilled) {
                    seriesTemplate.add(record);
                    seriesTemplateFilled = true;
                }
            }
            if (chartDeep == deep) {
                break;
            }
        }
        if (record instanceof ChartRecord) {
            if (record == chartRecord) {
                chartRecordIdx = idx;
                chartDeep = deep;
            }
        } else if (record instanceof SeriesRecord) {
            if (chartRecordIdx != -1) {
                seriesIdx++;
                lastSeriesDeep = deep;
            }
        }
        if (lastSeriesDeep != -1 && !seriesTemplateFilled) {
            seriesTemplate.add(record);
        }
    }
    /* check if a series was found */
    if (endSeriesRecordIdx == -1) {
        return null;
    }
    /* next index in the records list where the new series can be inserted */
    idx = endSeriesRecordIdx + 1;
    HSSFSeries newSeries = null;
    /* duplicate record of the template series */
    ArrayList<RecordBase> clonedRecords = new ArrayList<RecordBase>();
    for (final RecordBase record : seriesTemplate) {
        Record newRecord = null;
        if (record instanceof BeginRecord) {
            newRecord = new BeginRecord();
        } else if (record instanceof EndRecord) {
            newRecord = new EndRecord();
        } else if (record instanceof SeriesRecord) {
            SeriesRecord seriesRecord = (SeriesRecord) ((SeriesRecord) record).clone();
            newSeries = new HSSFSeries(seriesRecord);
            newRecord = seriesRecord;
        } else if (record instanceof LinkedDataRecord) {
            LinkedDataRecord linkedDataRecord = ((LinkedDataRecord) record).clone();
            if (newSeries != null) {
                newSeries.insertData(linkedDataRecord);
            }
            newRecord = linkedDataRecord;
        } else if (record instanceof DataFormatRecord) {
            DataFormatRecord dataFormatRecord = ((DataFormatRecord) record).clone();
            dataFormatRecord.setSeriesIndex((short) seriesIdx);
            dataFormatRecord.setSeriesNumber((short) seriesIdx);
            newRecord = dataFormatRecord;
        } else if (record instanceof SeriesTextRecord) {
            SeriesTextRecord seriesTextRecord = (SeriesTextRecord) ((SeriesTextRecord) record).clone();
            if (newSeries != null) {
                newSeries.setSeriesTitleText(seriesTextRecord);
            }
            newRecord = seriesTextRecord;
        } else if (record instanceof Record) {
            newRecord = (Record) ((Record) record).clone();
        }
        if (newRecord != null) {
            clonedRecords.add(newRecord);
        }
    }
    /* check if a user model series object was created */
    if (newSeries == null) {
        return null;
    }
    /* transfer series to record list */
    for (final RecordBase record : clonedRecords) {
        records.add(idx++, record);
    }
    return newSeries;
}
Also used : EndRecord(org.apache.poi.hssf.record.chart.EndRecord) 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) RecordBase(org.apache.poi.hssf.record.RecordBase) BeginRecord(org.apache.poi.hssf.record.chart.BeginRecord) DataFormatRecord(org.apache.poi.hssf.record.chart.DataFormatRecord) 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)

Aggregations

Record (org.apache.poi.hssf.record.Record)78 EOFRecord (org.apache.poi.hssf.record.EOFRecord)42 BOFRecord (org.apache.poi.hssf.record.BOFRecord)36 WindowTwoRecord (org.apache.poi.hssf.record.WindowTwoRecord)36 FormulaRecord (org.apache.poi.hssf.record.FormulaRecord)30 Test (org.junit.Test)25 DimensionsRecord (org.apache.poi.hssf.record.DimensionsRecord)24 NumberRecord (org.apache.poi.hssf.record.NumberRecord)24 RowRecord (org.apache.poi.hssf.record.RowRecord)24 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)23 NameRecord (org.apache.poi.hssf.record.NameRecord)23 ArrayList (java.util.ArrayList)21 EscherRecord (org.apache.poi.ddf.EscherRecord)21 BlankRecord (org.apache.poi.hssf.record.BlankRecord)21 DrawingRecord (org.apache.poi.hssf.record.DrawingRecord)21 UnknownRecord (org.apache.poi.hssf.record.UnknownRecord)19 BoundSheetRecord (org.apache.poi.hssf.record.BoundSheetRecord)18 MulBlankRecord (org.apache.poi.hssf.record.MulBlankRecord)18 StringRecord (org.apache.poi.hssf.record.StringRecord)18 NoteRecord (org.apache.poi.hssf.record.NoteRecord)17