Search in sources :

Example 11 with CTShape

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape in project tika by apache.

the class XSSFExcelExtractorDecorator method extractHyperLinksFromShape.

private void extractHyperLinksFromShape(CTShape ctShape, XHTMLContentHandler xhtml) throws SAXException {
    if (ctShape == null)
        return;
    CTShapeNonVisual nvSpPR = ctShape.getNvSpPr();
    if (nvSpPR == null)
        return;
    CTNonVisualDrawingProps cNvPr = nvSpPR.getCNvPr();
    if (cNvPr == null)
        return;
    CTHyperlink ctHyperlink = cNvPr.getHlinkClick();
    if (ctHyperlink == null)
        return;
    String url = drawingHyperlinks.get(ctHyperlink.getId());
    if (url != null) {
        xhtml.startElement("a", "href", url);
        xhtml.characters(url);
        xhtml.endElement("a");
    }
    CTHyperlink ctHoverHyperlink = cNvPr.getHlinkHover();
    if (ctHoverHyperlink == null)
        return;
    url = drawingHyperlinks.get(ctHoverHyperlink.getId());
    if (url != null) {
        xhtml.startElement("a", "href", url);
        xhtml.characters(url);
        xhtml.endElement("a");
    }
}
Also used : CTShapeNonVisual(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShapeNonVisual) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTHyperlink(org.openxmlformats.schemas.drawingml.x2006.main.CTHyperlink)

Example 12 with CTShape

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape in project poi by apache.

the class XSLFFreeformShape method prototype.

/**
     * @param shapeId 1-based shapeId
     */
static CTShape prototype(int shapeId) {
    CTShape ct = CTShape.Factory.newInstance();
    CTShapeNonVisual nvSpPr = ct.addNewNvSpPr();
    CTNonVisualDrawingProps cnv = nvSpPr.addNewCNvPr();
    cnv.setName("Freeform " + shapeId);
    cnv.setId(shapeId + 1);
    nvSpPr.addNewCNvSpPr();
    nvSpPr.addNewNvPr();
    CTShapeProperties spPr = ct.addNewSpPr();
    CTCustomGeometry2D geom = spPr.addNewCustGeom();
    geom.addNewAvLst();
    geom.addNewGdLst();
    geom.addNewAhLst();
    geom.addNewCxnLst();
    CTGeomRect rect = geom.addNewRect();
    rect.setR("r");
    rect.setB("b");
    rect.setT("t");
    rect.setL("l");
    geom.addNewPathLst();
    return ct;
}
Also used : CTShapeNonVisual(org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual) CTShapeProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties) CTCustomGeometry2D(org.openxmlformats.schemas.drawingml.x2006.main.CTCustomGeometry2D) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTGeomRect(org.openxmlformats.schemas.drawingml.x2006.main.CTGeomRect) CTShape(org.openxmlformats.schemas.presentationml.x2006.main.CTShape)

Example 13 with CTShape

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape in project poi by apache.

the class XSLFAutoShape method getTextBody.

protected CTTextBody getTextBody(boolean create) {
    CTShape shape = (CTShape) getXmlObject();
    CTTextBody txBody = shape.getTxBody();
    if (txBody == null && create) {
        txBody = shape.addNewTxBody();
        initTextBody(txBody);
    }
    return txBody;
}
Also used : CTShape(org.openxmlformats.schemas.presentationml.x2006.main.CTShape) CTTextBody(org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody)

Example 14 with CTShape

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape in project poi by apache.

the class XSSFDrawing method createSimpleShape.

/**
     * Creates a simple shape.  This includes such shapes as lines, rectangles,
     * and ovals.
     *
     * @param anchor    the client anchor describes how this group is attached
     *                  to the sheet.
     * @return  the newly created shape.
     */
public XSSFSimpleShape createSimpleShape(XSSFClientAnchor anchor) {
    long shapeId = newShapeId();
    CTTwoCellAnchor ctAnchor = createTwoCellAnchor(anchor);
    CTShape ctShape = ctAnchor.addNewSp();
    ctShape.set(XSSFSimpleShape.prototype());
    ctShape.getNvSpPr().getCNvPr().setId(shapeId);
    ctShape.getSpPr().setXfrm(createXfrm(anchor));
    XSSFSimpleShape shape = new XSSFSimpleShape(this, ctShape);
    shape.anchor = anchor;
    return shape;
}
Also used : CTShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape) CTTwoCellAnchor(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor)

Example 15 with CTShape

use of org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape in project poi by apache.

the class XSSFDrawing method createObjectData.

@Override
public XSSFObjectData createObjectData(ClientAnchor anchor, int storageId, int pictureIndex) {
    XSSFSheet sh = getSheet();
    PackagePart sheetPart = sh.getPackagePart();
    /*
         * The shape id of the ole object seems to be a legacy shape id.
         * 
         * see 5.3.2.1 legacyDrawing (Legacy Drawing Object):
         * Legacy Shape ID that is unique throughout the entire document.
         * Legacy shape IDs should be assigned based on which portion of the document the
         * drawing resides on. The assignment of these ids is broken down into clusters of
         * 1024 values. The first cluster is 1-1024, the second 1025-2048 and so on.
         *
         * Ole shapes seem to start with 1025 on the first sheet ...
         * and not sure, if the ids need to be reindexed when sheets are removed
         * or more than 1024 shapes are on a given sheet (see #51332 for a similar issue)
         */
    XSSFSheet sheet = getSheet();
    XSSFWorkbook wb = sheet.getWorkbook();
    int sheetIndex = wb.getSheetIndex(sheet);
    long shapeId = (sheetIndex + 1) * 1024 + newShapeId();
    // add reference to OLE part
    PackagePartName olePN;
    try {
        olePN = PackagingURIHelper.createPartName("/xl/embeddings/oleObject" + storageId + ".bin");
    } catch (InvalidFormatException e) {
        throw new POIXMLException(e);
    }
    PackageRelationship olePR = sheetPart.addRelationship(olePN, TargetMode.INTERNAL, POIXMLDocument.OLE_OBJECT_REL_TYPE);
    // add reference to image part
    XSSFPictureData imgPD = sh.getWorkbook().getAllPictures().get(pictureIndex);
    PackagePartName imgPN = imgPD.getPackagePart().getPartName();
    PackageRelationship imgSheetPR = sheetPart.addRelationship(imgPN, TargetMode.INTERNAL, PackageRelationshipTypes.IMAGE_PART);
    PackageRelationship imgDrawPR = getPackagePart().addRelationship(imgPN, TargetMode.INTERNAL, PackageRelationshipTypes.IMAGE_PART);
    // add OLE part metadata to sheet
    CTWorksheet cwb = sh.getCTWorksheet();
    CTOleObjects oo = cwb.isSetOleObjects() ? cwb.getOleObjects() : cwb.addNewOleObjects();
    CTOleObject ole1 = oo.addNewOleObject();
    ole1.setProgId("Package");
    ole1.setShapeId(shapeId);
    ole1.setId(olePR.getId());
    XmlCursor cur1 = ole1.newCursor();
    cur1.toEndToken();
    cur1.beginElement("objectPr", XSSFRelation.NS_SPREADSHEETML);
    cur1.insertAttributeWithValue("id", PackageRelationshipTypes.CORE_PROPERTIES_ECMA376_NS, imgSheetPR.getId());
    cur1.insertAttributeWithValue("defaultSize", "0");
    cur1.beginElement("anchor", XSSFRelation.NS_SPREADSHEETML);
    cur1.insertAttributeWithValue("moveWithCells", "1");
    CTTwoCellAnchor ctAnchor = createTwoCellAnchor((XSSFClientAnchor) anchor);
    XmlCursor cur2 = ctAnchor.newCursor();
    cur2.copyXmlContents(cur1);
    cur2.dispose();
    cur1.toParent();
    cur1.toFirstChild();
    cur1.setName(new QName(XSSFRelation.NS_SPREADSHEETML, "from"));
    cur1.toNextSibling();
    cur1.setName(new QName(XSSFRelation.NS_SPREADSHEETML, "to"));
    cur1.dispose();
    // add a new shape and link OLE & image part
    CTShape ctShape = ctAnchor.addNewSp();
    ctShape.set(XSSFObjectData.prototype());
    ctShape.getSpPr().setXfrm(createXfrm((XSSFClientAnchor) anchor));
    // workaround for not having the vmlDrawing filled
    CTBlipFillProperties blipFill = ctShape.getSpPr().addNewBlipFill();
    blipFill.addNewBlip().setEmbed(imgDrawPR.getId());
    blipFill.addNewStretch().addNewFillRect();
    CTNonVisualDrawingProps cNvPr = ctShape.getNvSpPr().getCNvPr();
    cNvPr.setId(shapeId);
    cNvPr.setName("Object " + shapeId);
    XmlCursor extCur = cNvPr.getExtLst().getExtArray(0).newCursor();
    extCur.toFirstChild();
    extCur.setAttributeText(new QName("spid"), "_x0000_s" + shapeId);
    extCur.dispose();
    XSSFObjectData shape = new XSSFObjectData(this, ctShape);
    shape.anchor = (XSSFClientAnchor) anchor;
    return shape;
}
Also used : PackagePartName(org.apache.poi.openxml4j.opc.PackagePartName) QName(javax.xml.namespace.QName) CTWorksheet(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTWorksheet) CTOleObjects(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTOleObjects) CTShape(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape) POIXMLException(org.apache.poi.POIXMLException) PackagePart(org.apache.poi.openxml4j.opc.PackagePart) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) XmlCursor(org.apache.xmlbeans.XmlCursor) PackageRelationship(org.apache.poi.openxml4j.opc.PackageRelationship) CTBlipFillProperties(org.openxmlformats.schemas.drawingml.x2006.main.CTBlipFillProperties) CTNonVisualDrawingProps(org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps) CTOleObject(org.openxmlformats.schemas.spreadsheetml.x2006.main.CTOleObject) CTTwoCellAnchor(org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor)

Aggregations

CTShape (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShape)8 CTNonVisualDrawingProps (org.openxmlformats.schemas.drawingml.x2006.main.CTNonVisualDrawingProps)6 CTTwoCellAnchor (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTTwoCellAnchor)5 CTShape (org.openxmlformats.schemas.presentationml.x2006.main.CTShape)5 CTShapeNonVisual (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTShapeNonVisual)4 PackageRelationship (org.apache.poi.openxml4j.opc.PackageRelationship)3 XmlCursor (org.apache.xmlbeans.XmlCursor)3 CTShapeProperties (org.openxmlformats.schemas.drawingml.x2006.main.CTShapeProperties)3 CTConnector (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTConnector)3 CTPicture (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTPicture)3 QName (javax.xml.namespace.QName)2 CTHyperlink (org.openxmlformats.schemas.drawingml.x2006.main.CTHyperlink)2 CTPresetGeometry2D (org.openxmlformats.schemas.drawingml.x2006.main.CTPresetGeometry2D)2 CTTextBody (org.openxmlformats.schemas.drawingml.x2006.main.CTTextBody)2 CTTransform2D (org.openxmlformats.schemas.drawingml.x2006.main.CTTransform2D)2 CTGroupShape (org.openxmlformats.schemas.drawingml.x2006.spreadsheetDrawing.CTGroupShape)2 CTShapeNonVisual (org.openxmlformats.schemas.presentationml.x2006.main.CTShapeNonVisual)2 Rectangle2D (java.awt.geom.Rectangle2D)1 POIXMLException (org.apache.poi.POIXMLException)1 InvalidFormatException (org.apache.poi.openxml4j.exceptions.InvalidFormatException)1