Search in sources :

Example 1 with DrawingGroupRecord

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

the class InternalWorkbook method createDrawingGroup.

/**
     * Creates a primary drawing group record.  If it already
     *  exists then it's modified.
     */
public void createDrawingGroup() {
    if (drawingManager == null) {
        EscherContainerRecord dggContainer = new EscherContainerRecord();
        EscherDggRecord dgg = new EscherDggRecord();
        EscherOptRecord opt = new EscherOptRecord();
        EscherSplitMenuColorsRecord splitMenuColors = new EscherSplitMenuColorsRecord();
        dggContainer.setRecordId((short) 0xF000);
        dggContainer.setOptions((short) 0x000F);
        dgg.setRecordId(EscherDggRecord.RECORD_ID);
        dgg.setOptions((short) 0x0000);
        dgg.setShapeIdMax(1024);
        dgg.setNumShapesSaved(0);
        dgg.setDrawingsSaved(0);
        dgg.setFileIdClusters(new EscherDggRecord.FileIdCluster[] {});
        drawingManager = new DrawingManager2(dgg);
        EscherContainerRecord bstoreContainer = null;
        if (!escherBSERecords.isEmpty()) {
            bstoreContainer = new EscherContainerRecord();
            bstoreContainer.setRecordId(EscherContainerRecord.BSTORE_CONTAINER);
            bstoreContainer.setOptions((short) ((escherBSERecords.size() << 4) | 0xF));
            for (EscherRecord escherRecord : escherBSERecords) {
                bstoreContainer.addChildRecord(escherRecord);
            }
        }
        opt.setRecordId((short) 0xF00B);
        opt.setOptions((short) 0x0033);
        opt.addEscherProperty(new EscherBoolProperty(EscherProperties.TEXT__SIZE_TEXT_TO_FIT_SHAPE, 524296));
        opt.addEscherProperty(new EscherRGBProperty(EscherProperties.FILL__FILLCOLOR, 0x08000041));
        opt.addEscherProperty(new EscherRGBProperty(EscherProperties.LINESTYLE__COLOR, 134217792));
        splitMenuColors.setRecordId((short) 0xF11E);
        splitMenuColors.setOptions((short) 0x0040);
        splitMenuColors.setColor1(0x0800000D);
        splitMenuColors.setColor2(0x0800000C);
        splitMenuColors.setColor3(0x08000017);
        splitMenuColors.setColor4(0x100000F7);
        dggContainer.addChildRecord(dgg);
        if (bstoreContainer != null) {
            dggContainer.addChildRecord(bstoreContainer);
        }
        dggContainer.addChildRecord(opt);
        dggContainer.addChildRecord(splitMenuColors);
        int dgLoc = findFirstRecordLocBySid(DrawingGroupRecord.sid);
        if (dgLoc == -1) {
            DrawingGroupRecord drawingGroup = new DrawingGroupRecord();
            drawingGroup.addEscherRecord(dggContainer);
            int loc = findFirstRecordLocBySid(CountryRecord.sid);
            getRecords().add(loc + 1, drawingGroup);
        } else {
            DrawingGroupRecord drawingGroup = new DrawingGroupRecord();
            drawingGroup.addEscherRecord(dggContainer);
            getRecords().set(dgLoc, drawingGroup);
        }
    }
}
Also used : EscherSplitMenuColorsRecord(org.apache.poi.ddf.EscherSplitMenuColorsRecord) DrawingGroupRecord(org.apache.poi.hssf.record.DrawingGroupRecord) EscherBoolProperty(org.apache.poi.ddf.EscherBoolProperty) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) EscherOptRecord(org.apache.poi.ddf.EscherOptRecord) EscherRGBProperty(org.apache.poi.ddf.EscherRGBProperty)

Example 2 with DrawingGroupRecord

use of org.apache.poi.hssf.record.DrawingGroupRecord 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 3 with DrawingGroupRecord

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

the class InternalWorkbook method addBSERecord.

public int addBSERecord(EscherBSERecord e) {
    createDrawingGroup();
    // maybe we don't need that as an instance variable anymore
    escherBSERecords.add(e);
    int dgLoc = findFirstRecordLocBySid(DrawingGroupRecord.sid);
    DrawingGroupRecord drawingGroup = (DrawingGroupRecord) getRecords().get(dgLoc);
    EscherContainerRecord dggContainer = (EscherContainerRecord) drawingGroup.getEscherRecord(0);
    EscherContainerRecord bstoreContainer;
    if (dggContainer.getChild(1).getRecordId() == EscherContainerRecord.BSTORE_CONTAINER) {
        bstoreContainer = (EscherContainerRecord) dggContainer.getChild(1);
    } else {
        bstoreContainer = new EscherContainerRecord();
        bstoreContainer.setRecordId(EscherContainerRecord.BSTORE_CONTAINER);
        List<EscherRecord> childRecords = dggContainer.getChildRecords();
        childRecords.add(1, bstoreContainer);
        dggContainer.setChildRecords(childRecords);
    }
    bstoreContainer.setOptions((short) ((escherBSERecords.size() << 4) | 0xF));
    bstoreContainer.addChildRecord(e);
    return escherBSERecords.size();
}
Also used : DrawingGroupRecord(org.apache.poi.hssf.record.DrawingGroupRecord) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherRecord(org.apache.poi.ddf.EscherRecord)

Example 4 with DrawingGroupRecord

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

the class BiffDrawingToXml method writeToFile.

public static void writeToFile(OutputStream fos, InputStream xlsWorkbook, boolean excludeWorkbookRecords, String[] params) throws IOException {
    HSSFWorkbook workbook = new HSSFWorkbook(xlsWorkbook);
    InternalWorkbook internalWorkbook = workbook.getInternalWorkbook();
    DrawingGroupRecord r = (DrawingGroupRecord) internalWorkbook.findFirstRecordBySid(DrawingGroupRecord.sid);
    StringBuilder builder = new StringBuilder();
    builder.append("<workbook>\n");
    String tab = "\t";
    if (!excludeWorkbookRecords && r != null) {
        r.decode();
        List<EscherRecord> escherRecords = r.getEscherRecords();
        for (EscherRecord record : escherRecords) {
            builder.append(record.toXml(tab));
        }
    }
    List<Integer> sheets = getSheetsIndexes(params, workbook);
    for (Integer i : sheets) {
        HSSFPatriarch p = workbook.getSheetAt(i).getDrawingPatriarch();
        if (p != null) {
            builder.append(tab).append("<sheet").append(i).append(">\n");
            builder.append(p.getBoundAggregate().toXml(tab + "\t"));
            builder.append(tab).append("</sheet").append(i).append(">\n");
        }
    }
    builder.append("</workbook>\n");
    fos.write(builder.toString().getBytes(StringUtil.UTF8));
    fos.close();
    workbook.close();
}
Also used : HSSFPatriarch(org.apache.poi.hssf.usermodel.HSSFPatriarch) DrawingGroupRecord(org.apache.poi.hssf.record.DrawingGroupRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) InternalWorkbook(org.apache.poi.hssf.model.InternalWorkbook)

Example 5 with DrawingGroupRecord

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

the class HSSFWorkbook method dumpDrawingGroupRecords.

/**
     * Spits out a list of all the drawing records in the workbook.
     */
public void dumpDrawingGroupRecords(boolean fat) {
    DrawingGroupRecord r = (DrawingGroupRecord) workbook.findFirstRecordBySid(DrawingGroupRecord.sid);
    r.decode();
    List<EscherRecord> escherRecords = r.getEscherRecords();
    PrintWriter w = new PrintWriter(new OutputStreamWriter(System.out, Charset.defaultCharset()));
    for (EscherRecord escherRecord : escherRecords) {
        if (fat) {
            System.out.println(escherRecord);
        } else {
            escherRecord.display(w, 0);
        }
    }
    w.flush();
}
Also used : DrawingGroupRecord(org.apache.poi.hssf.record.DrawingGroupRecord) OutputStreamWriter(java.io.OutputStreamWriter) EscherRecord(org.apache.poi.ddf.EscherRecord) PrintWriter(java.io.PrintWriter)

Aggregations

EscherRecord (org.apache.poi.ddf.EscherRecord)5 DrawingGroupRecord (org.apache.poi.hssf.record.DrawingGroupRecord)5 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)3 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)2 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)2 EscherSplitMenuColorsRecord (org.apache.poi.ddf.EscherSplitMenuColorsRecord)2 OutputStreamWriter (java.io.OutputStreamWriter)1 PrintWriter (java.io.PrintWriter)1 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)1 EscherBoolProperty (org.apache.poi.ddf.EscherBoolProperty)1 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)1 EscherRGBProperty (org.apache.poi.ddf.EscherRGBProperty)1 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)1 InternalWorkbook (org.apache.poi.hssf.model.InternalWorkbook)1 BOFRecord (org.apache.poi.hssf.record.BOFRecord)1 BackupRecord (org.apache.poi.hssf.record.BackupRecord)1 BookBoolRecord (org.apache.poi.hssf.record.BookBoolRecord)1 BoundSheetRecord (org.apache.poi.hssf.record.BoundSheetRecord)1 CodepageRecord (org.apache.poi.hssf.record.CodepageRecord)1 CountryRecord (org.apache.poi.hssf.record.CountryRecord)1