Search in sources :

Example 41 with Record

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

the class InternalWorkbook method findDrawingGroup.

/**
     * Finds the primary drawing group, if one already exists
     *
     * @return the primary drawing group
     */
public DrawingManager2 findDrawingGroup() {
    if (drawingManager != null) {
        // We already have it!
        return drawingManager;
    }
    // Need to find a DrawingGroupRecord that contains a EscherDggRecord
    for (Record r : records) {
        if (!(r instanceof DrawingGroupRecord)) {
            continue;
        }
        DrawingGroupRecord dg = (DrawingGroupRecord) r;
        dg.processChildRecords();
        drawingManager = findDrawingManager(dg, escherBSERecords);
        if (drawingManager != null) {
            return drawingManager;
        }
    }
    // TODO: we've already scanned the records, why should this work any better now?
    // Look for the DrawingGroup record
    DrawingGroupRecord dg = (DrawingGroupRecord) findFirstRecordBySid(DrawingGroupRecord.sid);
    drawingManager = findDrawingManager(dg, escherBSERecords);
    return drawingManager;
}
Also used : DrawingGroupRecord(org.apache.poi.hssf.record.DrawingGroupRecord) WindowProtectRecord(org.apache.poi.hssf.record.WindowProtectRecord) PasswordRev4Record(org.apache.poi.hssf.record.PasswordRev4Record) DateWindow1904Record(org.apache.poi.hssf.record.DateWindow1904Record) FormatRecord(org.apache.poi.hssf.record.FormatRecord) BookBoolRecord(org.apache.poi.hssf.record.BookBoolRecord) StyleRecord(org.apache.poi.hssf.record.StyleRecord) RecalcIdRecord(org.apache.poi.hssf.record.RecalcIdRecord) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) HideObjRecord(org.apache.poi.hssf.record.HideObjRecord) Record(org.apache.poi.hssf.record.Record) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) HyperlinkRecord(org.apache.poi.hssf.record.HyperlinkRecord) ProtectionRev4Record(org.apache.poi.hssf.record.ProtectionRev4Record) EOFRecord(org.apache.poi.hssf.record.EOFRecord) MMSRecord(org.apache.poi.hssf.record.MMSRecord) PrecisionRecord(org.apache.poi.hssf.record.PrecisionRecord) BoundSheetRecord(org.apache.poi.hssf.record.BoundSheetRecord) CountryRecord(org.apache.poi.hssf.record.CountryRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) NameCommentRecord(org.apache.poi.hssf.record.NameCommentRecord) FnGroupCountRecord(org.apache.poi.hssf.record.FnGroupCountRecord) DrawingGroupRecord(org.apache.poi.hssf.record.DrawingGroupRecord) BackupRecord(org.apache.poi.hssf.record.BackupRecord) EscherSplitMenuColorsRecord(org.apache.poi.ddf.EscherSplitMenuColorsRecord) ExternSheetRecord(org.apache.poi.hssf.record.ExternSheetRecord) WriteAccessRecord(org.apache.poi.hssf.record.WriteAccessRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) CodepageRecord(org.apache.poi.hssf.record.CodepageRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) FilePassRecord(org.apache.poi.hssf.record.FilePassRecord) FontRecord(org.apache.poi.hssf.record.FontRecord) UseSelFSRecord(org.apache.poi.hssf.record.UseSelFSRecord) WindowOneRecord(org.apache.poi.hssf.record.WindowOneRecord) WriteProtectRecord(org.apache.poi.hssf.record.WriteProtectRecord) ProtectRecord(org.apache.poi.hssf.record.ProtectRecord) InterfaceHdrRecord(org.apache.poi.hssf.record.InterfaceHdrRecord) DSFRecord(org.apache.poi.hssf.record.DSFRecord) InterfaceEndRecord(org.apache.poi.hssf.record.InterfaceEndRecord) SupBookRecord(org.apache.poi.hssf.record.SupBookRecord) SSTRecord(org.apache.poi.hssf.record.SSTRecord) TabIdRecord(org.apache.poi.hssf.record.TabIdRecord) PasswordRecord(org.apache.poi.hssf.record.PasswordRecord) PaletteRecord(org.apache.poi.hssf.record.PaletteRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) ExtSSTRecord(org.apache.poi.hssf.record.ExtSSTRecord) ExtendedFormatRecord(org.apache.poi.hssf.record.ExtendedFormatRecord) FileSharingRecord(org.apache.poi.hssf.record.FileSharingRecord) RefreshAllRecord(org.apache.poi.hssf.record.RefreshAllRecord)

Example 42 with Record

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

the class InternalWorkbook method createWorkbook.

/**
     * Creates an empty workbook object with three blank sheets and all the empty
     * fields.  Use this to create a workbook from scratch.
     *
     * @return an empty workbook object
     */
public static InternalWorkbook createWorkbook() {
    LOG.log(DEBUG, "creating new workbook from scratch");
    InternalWorkbook retval = new InternalWorkbook();
    List<Record> records = new ArrayList<Record>(30);
    retval.records.setRecords(records);
    List<FormatRecord> formats = retval.formats;
    records.add(createBOF());
    records.add(new InterfaceHdrRecord(CODEPAGE));
    records.add(createMMS());
    records.add(InterfaceEndRecord.instance);
    records.add(createWriteAccess());
    records.add(createCodepage());
    records.add(createDSF());
    records.add(createTabId());
    retval.records.setTabpos(records.size() - 1);
    records.add(createFnGroupCount());
    records.add(createWindowProtect());
    records.add(createProtect());
    retval.records.setProtpos(records.size() - 1);
    records.add(createPassword());
    records.add(createProtectionRev4());
    records.add(createPasswordRev4());
    retval.windowOne = createWindowOne();
    records.add(retval.windowOne);
    records.add(createBackup());
    retval.records.setBackuppos(records.size() - 1);
    records.add(createHideObj());
    records.add(createDateWindow1904());
    records.add(createPrecision());
    records.add(createRefreshAll());
    records.add(createBookBool());
    records.add(createFont());
    records.add(createFont());
    records.add(createFont());
    records.add(createFont());
    // last font record position
    retval.records.setFontpos(records.size() - 1);
    retval.numfonts = 4;
    // set up format records
    for (int i = 0; i <= 7; i++) {
        FormatRecord rec = createFormat(i);
        retval.maxformatid = retval.maxformatid >= rec.getIndexCode() ? retval.maxformatid : rec.getIndexCode();
        formats.add(rec);
        records.add(rec);
    }
    for (int k = 0; k < 21; k++) {
        records.add(InternalWorkbook.createExtendedFormat(k));
        retval.numxfs++;
    }
    retval.records.setXfpos(records.size() - 1);
    for (int k = 0; k < 6; k++) {
        records.add(InternalWorkbook.createStyle(k));
    }
    records.add(InternalWorkbook.createUseSelFS());
    // now just do 1
    int nBoundSheets = 1;
    for (int k = 0; k < nBoundSheets; k++) {
        BoundSheetRecord bsr = createBoundSheet(k);
        records.add(bsr);
        retval.boundsheets.add(bsr);
        retval.records.setBspos(records.size() - 1);
    }
    records.add(InternalWorkbook.createCountry());
    for (int k = 0; k < nBoundSheets; k++) {
        retval.getOrCreateLinkTable().checkExternSheet(k);
    }
    retval.sst = new SSTRecord();
    records.add(retval.sst);
    records.add(InternalWorkbook.createExtendedSST());
    records.add(EOFRecord.instance);
    LOG.log(DEBUG, "exit create new workbook from scratch");
    return retval;
}
Also used : InterfaceHdrRecord(org.apache.poi.hssf.record.InterfaceHdrRecord) ArrayList(java.util.ArrayList) WindowProtectRecord(org.apache.poi.hssf.record.WindowProtectRecord) PasswordRev4Record(org.apache.poi.hssf.record.PasswordRev4Record) DateWindow1904Record(org.apache.poi.hssf.record.DateWindow1904Record) FormatRecord(org.apache.poi.hssf.record.FormatRecord) BookBoolRecord(org.apache.poi.hssf.record.BookBoolRecord) StyleRecord(org.apache.poi.hssf.record.StyleRecord) RecalcIdRecord(org.apache.poi.hssf.record.RecalcIdRecord) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) HideObjRecord(org.apache.poi.hssf.record.HideObjRecord) Record(org.apache.poi.hssf.record.Record) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) HyperlinkRecord(org.apache.poi.hssf.record.HyperlinkRecord) ProtectionRev4Record(org.apache.poi.hssf.record.ProtectionRev4Record) EOFRecord(org.apache.poi.hssf.record.EOFRecord) MMSRecord(org.apache.poi.hssf.record.MMSRecord) PrecisionRecord(org.apache.poi.hssf.record.PrecisionRecord) BoundSheetRecord(org.apache.poi.hssf.record.BoundSheetRecord) CountryRecord(org.apache.poi.hssf.record.CountryRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) NameCommentRecord(org.apache.poi.hssf.record.NameCommentRecord) FnGroupCountRecord(org.apache.poi.hssf.record.FnGroupCountRecord) DrawingGroupRecord(org.apache.poi.hssf.record.DrawingGroupRecord) BackupRecord(org.apache.poi.hssf.record.BackupRecord) EscherSplitMenuColorsRecord(org.apache.poi.ddf.EscherSplitMenuColorsRecord) ExternSheetRecord(org.apache.poi.hssf.record.ExternSheetRecord) WriteAccessRecord(org.apache.poi.hssf.record.WriteAccessRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) CodepageRecord(org.apache.poi.hssf.record.CodepageRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) FilePassRecord(org.apache.poi.hssf.record.FilePassRecord) FontRecord(org.apache.poi.hssf.record.FontRecord) UseSelFSRecord(org.apache.poi.hssf.record.UseSelFSRecord) WindowOneRecord(org.apache.poi.hssf.record.WindowOneRecord) WriteProtectRecord(org.apache.poi.hssf.record.WriteProtectRecord) ProtectRecord(org.apache.poi.hssf.record.ProtectRecord) InterfaceHdrRecord(org.apache.poi.hssf.record.InterfaceHdrRecord) DSFRecord(org.apache.poi.hssf.record.DSFRecord) InterfaceEndRecord(org.apache.poi.hssf.record.InterfaceEndRecord) SupBookRecord(org.apache.poi.hssf.record.SupBookRecord) SSTRecord(org.apache.poi.hssf.record.SSTRecord) TabIdRecord(org.apache.poi.hssf.record.TabIdRecord) PasswordRecord(org.apache.poi.hssf.record.PasswordRecord) PaletteRecord(org.apache.poi.hssf.record.PaletteRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) ExtSSTRecord(org.apache.poi.hssf.record.ExtSSTRecord) ExtendedFormatRecord(org.apache.poi.hssf.record.ExtendedFormatRecord) FileSharingRecord(org.apache.poi.hssf.record.FileSharingRecord) RefreshAllRecord(org.apache.poi.hssf.record.RefreshAllRecord) FormatRecord(org.apache.poi.hssf.record.FormatRecord) ExtendedFormatRecord(org.apache.poi.hssf.record.ExtendedFormatRecord) SSTRecord(org.apache.poi.hssf.record.SSTRecord) ExtSSTRecord(org.apache.poi.hssf.record.ExtSSTRecord) BoundSheetRecord(org.apache.poi.hssf.record.BoundSheetRecord)

Example 43 with Record

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

the class InternalWorkbook method serialize.

/**
     * Serializes all records int the worksheet section into a big byte array. Use
     * this to write the Workbook out.
     * @param offset of the data to be written
     * @param data array of bytes to write this to
     * @return the length of serialized bytes
     */
public int serialize(int offset, byte[] data) {
    LOG.log(DEBUG, "Serializing Workbook with offsets");
    int pos = 0;
    SSTRecord lSST = null;
    int sstPos = 0;
    boolean wroteBoundSheets = false;
    for (Record record : records) {
        int len = 0;
        if (record instanceof SSTRecord) {
            lSST = (SSTRecord) record;
            sstPos = pos;
        }
        if (record.getSid() == ExtSSTRecord.sid && lSST != null) {
            record = lSST.createExtSSTRecord(sstPos + offset);
        }
        if (record instanceof BoundSheetRecord) {
            if (!wroteBoundSheets) {
                for (BoundSheetRecord bsr : boundsheets) {
                    len += bsr.serialize(pos + offset + len, data);
                }
                wroteBoundSheets = true;
            }
        } else {
            len = record.serialize(pos + offset, data);
        }
        pos += len;
    }
    LOG.log(DEBUG, "Exiting serialize workbook");
    return pos;
}
Also used : WindowProtectRecord(org.apache.poi.hssf.record.WindowProtectRecord) PasswordRev4Record(org.apache.poi.hssf.record.PasswordRev4Record) DateWindow1904Record(org.apache.poi.hssf.record.DateWindow1904Record) FormatRecord(org.apache.poi.hssf.record.FormatRecord) BookBoolRecord(org.apache.poi.hssf.record.BookBoolRecord) StyleRecord(org.apache.poi.hssf.record.StyleRecord) RecalcIdRecord(org.apache.poi.hssf.record.RecalcIdRecord) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) HideObjRecord(org.apache.poi.hssf.record.HideObjRecord) Record(org.apache.poi.hssf.record.Record) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) HyperlinkRecord(org.apache.poi.hssf.record.HyperlinkRecord) ProtectionRev4Record(org.apache.poi.hssf.record.ProtectionRev4Record) EOFRecord(org.apache.poi.hssf.record.EOFRecord) MMSRecord(org.apache.poi.hssf.record.MMSRecord) PrecisionRecord(org.apache.poi.hssf.record.PrecisionRecord) BoundSheetRecord(org.apache.poi.hssf.record.BoundSheetRecord) CountryRecord(org.apache.poi.hssf.record.CountryRecord) EscherSpRecord(org.apache.poi.ddf.EscherSpRecord) NameCommentRecord(org.apache.poi.hssf.record.NameCommentRecord) FnGroupCountRecord(org.apache.poi.hssf.record.FnGroupCountRecord) DrawingGroupRecord(org.apache.poi.hssf.record.DrawingGroupRecord) BackupRecord(org.apache.poi.hssf.record.BackupRecord) EscherSplitMenuColorsRecord(org.apache.poi.ddf.EscherSplitMenuColorsRecord) ExternSheetRecord(org.apache.poi.hssf.record.ExternSheetRecord) WriteAccessRecord(org.apache.poi.hssf.record.WriteAccessRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) CodepageRecord(org.apache.poi.hssf.record.CodepageRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) NameRecord(org.apache.poi.hssf.record.NameRecord) BOFRecord(org.apache.poi.hssf.record.BOFRecord) FilePassRecord(org.apache.poi.hssf.record.FilePassRecord) FontRecord(org.apache.poi.hssf.record.FontRecord) UseSelFSRecord(org.apache.poi.hssf.record.UseSelFSRecord) WindowOneRecord(org.apache.poi.hssf.record.WindowOneRecord) WriteProtectRecord(org.apache.poi.hssf.record.WriteProtectRecord) ProtectRecord(org.apache.poi.hssf.record.ProtectRecord) InterfaceHdrRecord(org.apache.poi.hssf.record.InterfaceHdrRecord) DSFRecord(org.apache.poi.hssf.record.DSFRecord) InterfaceEndRecord(org.apache.poi.hssf.record.InterfaceEndRecord) SupBookRecord(org.apache.poi.hssf.record.SupBookRecord) SSTRecord(org.apache.poi.hssf.record.SSTRecord) TabIdRecord(org.apache.poi.hssf.record.TabIdRecord) PasswordRecord(org.apache.poi.hssf.record.PasswordRecord) PaletteRecord(org.apache.poi.hssf.record.PaletteRecord) EscherDgRecord(org.apache.poi.ddf.EscherDgRecord) ExtSSTRecord(org.apache.poi.hssf.record.ExtSSTRecord) ExtendedFormatRecord(org.apache.poi.hssf.record.ExtendedFormatRecord) FileSharingRecord(org.apache.poi.hssf.record.FileSharingRecord) RefreshAllRecord(org.apache.poi.hssf.record.RefreshAllRecord) SSTRecord(org.apache.poi.hssf.record.SSTRecord) ExtSSTRecord(org.apache.poi.hssf.record.ExtSSTRecord) BoundSheetRecord(org.apache.poi.hssf.record.BoundSheetRecord)

Example 44 with Record

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

the class InternalSheet method findFirstRecordLocBySid.

/**
     * Finds the first occurrence of a record matching a particular sid and
     * returns it's position.
     * @param sid   the sid to search for
     * @return  the record position of the matching record or -1 if no match
     *          is made.
     */
public int findFirstRecordLocBySid(short sid) {
    // TODO - remove this method
    int max = _records.size();
    for (int i = 0; i < max; i++) {
        Object rb = _records.get(i);
        if (!(rb instanceof Record)) {
            continue;
        }
        Record record = (Record) rb;
        if (record.getSid() == sid) {
            return i;
        }
    }
    return -1;
}
Also used : 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)

Example 45 with Record

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

the class EFBiffViewer method run.

public void run() throws IOException {
    NPOIFSFileSystem fs = new NPOIFSFileSystem(new File(file), true);
    try {
        InputStream din = BiffViewer.getPOIFSInputStream(fs);
        try {
            HSSFRequest req = new HSSFRequest();
            req.addListenerForAllRecords(new HSSFListener() {

                public void processRecord(Record rec) {
                    System.out.println(rec);
                }
            });
            HSSFEventFactory factory = new HSSFEventFactory();
            factory.processEvents(req, din);
        } finally {
            din.close();
        }
    } finally {
        fs.close();
    }
}
Also used : HSSFEventFactory(org.apache.poi.hssf.eventusermodel.HSSFEventFactory) NPOIFSFileSystem(org.apache.poi.poifs.filesystem.NPOIFSFileSystem) InputStream(java.io.InputStream) HSSFRequest(org.apache.poi.hssf.eventusermodel.HSSFRequest) Record(org.apache.poi.hssf.record.Record) HSSFListener(org.apache.poi.hssf.eventusermodel.HSSFListener) File(java.io.File)

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