Search in sources :

Example 21 with EscherRecord

use of org.apache.poi.ddf.EscherRecord in project poi by apache.

the class InternalWorkbook method findDrawingManager.

private static DrawingManager2 findDrawingManager(DrawingGroupRecord dg, List<EscherBSERecord> escherBSERecords) {
    if (dg == null) {
        return null;
    }
    // If there is one, does it have a EscherDggRecord?
    EscherContainerRecord cr = dg.getEscherContainer();
    if (cr == null) {
        return null;
    }
    EscherDggRecord dgg = null;
    EscherContainerRecord bStore = null;
    for (EscherRecord er : cr) {
        if (er instanceof EscherDggRecord) {
            dgg = (EscherDggRecord) er;
        } else if (er.getRecordId() == EscherContainerRecord.BSTORE_CONTAINER) {
            bStore = (EscherContainerRecord) er;
        }
    }
    if (dgg == null) {
        return null;
    }
    DrawingManager2 dm = new DrawingManager2(dgg);
    if (bStore != null) {
        for (EscherRecord bs : bStore.getChildRecords()) {
            if (bs instanceof EscherBSERecord) {
                escherBSERecords.add((EscherBSERecord) bs);
            }
        }
    }
    return dm;
}
Also used : EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherDggRecord(org.apache.poi.ddf.EscherDggRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord)

Example 22 with EscherRecord

use of org.apache.poi.ddf.EscherRecord 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 23 with EscherRecord

use of org.apache.poi.ddf.EscherRecord 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 24 with EscherRecord

use of org.apache.poi.ddf.EscherRecord in project poi by apache.

the class HSLFFill method getEscherBSERecord.

@SuppressWarnings("resource")
protected EscherBSERecord getEscherBSERecord(int idx) {
    HSLFSheet sheet = shape.getSheet();
    if (sheet == null) {
        LOG.log(POILogger.DEBUG, "Fill has not yet been assigned to a sheet");
        return null;
    }
    HSLFSlideShow ppt = sheet.getSlideShow();
    Document doc = ppt.getDocumentRecord();
    EscherContainerRecord dggContainer = doc.getPPDrawingGroup().getDggContainer();
    EscherContainerRecord bstore = HSLFShape.getEscherChild(dggContainer, EscherContainerRecord.BSTORE_CONTAINER);
    if (bstore == null) {
        LOG.log(POILogger.DEBUG, "EscherContainerRecord.BSTORE_CONTAINER was not found ");
        return null;
    }
    List<EscherRecord> lst = bstore.getChildRecords();
    return (EscherBSERecord) lst.get(idx - 1);
}
Also used : EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) Document(org.apache.poi.hslf.record.Document) EscherBSERecord(org.apache.poi.ddf.EscherBSERecord)

Example 25 with EscherRecord

use of org.apache.poi.ddf.EscherRecord in project poi by apache.

the class HSLFShapeFactory method createShapeGroup.

public static HSLFGroupShape createShapeGroup(EscherContainerRecord spContainer, ShapeContainer<HSLFShape, HSLFTextParagraph> parent) {
    boolean isTable = false;
    EscherContainerRecord ecr = (EscherContainerRecord) spContainer.getChild(0);
    EscherRecord opt = HSLFShape.getEscherChild(ecr, RecordTypes.EscherUserDefined);
    if (opt != null) {
        EscherPropertyFactory f = new EscherPropertyFactory();
        List<EscherProperty> props = f.createProperties(opt.serialize(), 8, opt.getInstance());
        for (EscherProperty ep : props) {
            if (ep.getPropertyNumber() == EscherProperties.GROUPSHAPE__TABLEPROPERTIES && ep instanceof EscherSimpleProperty && (((EscherSimpleProperty) ep).getPropertyValue() & 1) == 1) {
                isTable = true;
                break;
            }
        }
    }
    HSLFGroupShape group;
    if (isTable) {
        group = new HSLFTable(spContainer, parent);
    } else {
        group = new HSLFGroupShape(spContainer, parent);
    }
    return group;
}
Also used : EscherSimpleProperty(org.apache.poi.ddf.EscherSimpleProperty) EscherContainerRecord(org.apache.poi.ddf.EscherContainerRecord) EscherRecord(org.apache.poi.ddf.EscherRecord) EscherPropertyFactory(org.apache.poi.ddf.EscherPropertyFactory) EscherProperty(org.apache.poi.ddf.EscherProperty)

Aggregations

EscherRecord (org.apache.poi.ddf.EscherRecord)42 EscherContainerRecord (org.apache.poi.ddf.EscherContainerRecord)20 EscherBSERecord (org.apache.poi.ddf.EscherBSERecord)10 DefaultEscherRecordFactory (org.apache.poi.ddf.DefaultEscherRecordFactory)9 ArrayList (java.util.ArrayList)7 EscherRecordFactory (org.apache.poi.ddf.EscherRecordFactory)6 EscherSpRecord (org.apache.poi.ddf.EscherSpRecord)6 EscherTextboxRecord (org.apache.poi.ddf.EscherTextboxRecord)6 DrawingGroupRecord (org.apache.poi.hssf.record.DrawingGroupRecord)5 EscherBlipRecord (org.apache.poi.ddf.EscherBlipRecord)4 EscherClientDataRecord (org.apache.poi.ddf.EscherClientDataRecord)4 EscherDgRecord (org.apache.poi.ddf.EscherDgRecord)4 EscherOptRecord (org.apache.poi.ddf.EscherOptRecord)4 EscherSimpleProperty (org.apache.poi.ddf.EscherSimpleProperty)4 Document (org.apache.poi.hslf.record.Document)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 AbstractEscherOptRecord (org.apache.poi.ddf.AbstractEscherOptRecord)3 EscherDggRecord (org.apache.poi.ddf.EscherDggRecord)3 EscherSpgrRecord (org.apache.poi.ddf.EscherSpgrRecord)3 EscherProperty (org.apache.poi.ddf.EscherProperty)2