/** * Assign a DrawingML chart to the graphic frame. */ protected void setChart(XSSFChart chart, String relId) { CTGraphicalObjectData data = graphicFrame.getGraphic().addNewGraphicData(); appendChartElement(data, relId); chart.setGraphicFrame(this); }
private static String getUri(CTGraphicalObjectFrame shape) { final CTGraphicalObject g = shape.getGraphic(); if (g == null) { return null; } CTGraphicalObjectData gd = g.getGraphicData(); return (gd == null) ? null : gd.getUri(); }
/** * Construct a new XSSFGraphicFrame object. * * @param drawing the XSSFDrawing that owns this frame * @param ctGraphicFrame the XML bean that stores this frame content */ protected XSSFGraphicFrame(XSSFDrawing drawing, CTGraphicalObjectFrame ctGraphicFrame) { this.drawing = drawing; // protected field on XSSFShape this.graphicFrame = ctGraphicFrame; // TODO: there may be a better way to delegate this CTGraphicalObjectData graphicData = graphicFrame.getGraphic().getGraphicData(); if (graphicData != null) { NodeList nodes = graphicData.getDomNode().getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { final Node node = nodes.item(i); // if the frame references a chart, associate the chart with this instance if (node.getNodeName().equals("c:chart")) { // this better succeed or the document is invalid POIXMLDocumentPart relation = drawing.getRelationById(node.getAttributes().getNamedItem("r:id").getNodeValue()); // Do XWPF charts need similar treatment? if (relation instanceof XSSFChart) { ((XSSFChart) relation).setGraphicFrame(this); } } } } }
static CTGraphicalObjectFrame prototype(int shapeId){ CTGraphicalObjectFrame frame = CTGraphicalObjectFrame.Factory.newInstance(); CTGraphicalObjectFrameNonVisual nvGr = frame.addNewNvGraphicFramePr(); CTNonVisualDrawingProps cnv = nvGr.addNewCNvPr(); cnv.setName("Table " + shapeId); cnv.setId(shapeId); nvGr.addNewCNvGraphicFramePr().addNewGraphicFrameLocks().setNoGrp(true); nvGr.addNewNvPr(); frame.addNewXfrm(); CTGraphicalObjectData gr = frame.addNewGraphic().addNewGraphicData(); XmlCursor grCur = gr.newCursor(); grCur.toNextToken(); grCur.beginElement(new QName(XSLFRelation.NS_DRAWINGML, "tbl")); CTTable tbl = CTTable.Factory.newInstance(); tbl.addNewTblPr(); tbl.addNewTblGrid(); XmlCursor tblCur = tbl.newCursor(); tblCur.moveXmlContents(grCur); tblCur.dispose(); grCur.dispose(); gr.setUri(TABLE_URI); return frame; }
@Override void copy(XSLFShape sh){ super.copy(sh); CTGraphicalObjectData data = ((CTGraphicalObjectFrame)getXmlObject()).getGraphic().getGraphicData(); String uri = data.getUri(); if(uri.equals("http://schemas.openxmlformats.org/drawingml/2006/diagram")){ copyDiagram(data, (XSLFGraphicFrame)sh); } if(uri.equals("http://schemas.openxmlformats.org/drawingml/2006/chart")){ copyChart(data, (XSLFGraphicFrame)sh); } else { // TODO support other types of objects } }
CTGraphicalObjectData gr = frame.addNewGraphic().addNewGraphicData(); gr.setUri(OLE_URI); XmlCursor grCur = gr.newCursor();
/*package*/ XSLFObjectShape(CTGraphicalObjectFrame shape, XSLFSheet sheet){ super(shape, sheet); CTGraphicalObjectData god = shape.getGraphic().getGraphicData(); XmlCursor xc = god.newCursor(); // select oleObj potentially under AlternateContent // usually the mc:Choice element will be selected first xc.selectPath("declare namespace p='"+PML_NS+"' .//p:oleObj"); try { if (!xc.toNextSelection()) { throw new IllegalStateException("p:oleObj element was not found in\n " + god); } XmlObject xo = xc.getObject(); // Pesky XmlBeans bug - see Bugzilla #49934 // it never happens when using the full ooxml-schemas jar but may happen with the abridged poi-ooxml-schemas if (xo instanceof XmlAnyTypeImpl){ String errStr = "Schemas (*.xsb) for CTOleObject can't be loaded - usually this happens when OSGI " + "loading is used and the thread context classloader has no reference to " + "the xmlbeans classes - use POIXMLTypeLoader.setClassLoader() to set the loader, " + "e.g. with CTOleObject.class.getClassLoader()" ; throw new IllegalStateException(errStr); } _oleObject = (CTOleObject)xo; } finally { xc.dispose(); } }
/** * Assign a DrawingML chart to the graphic frame. */ protected void setChart(XSSFChart chart, String relId) { CTGraphicalObjectData data = graphicFrame.getGraphic().addNewGraphicData(); appendChartElement(data, relId); chart.setGraphicFrame(this); }
/*package*/ XSLFTable(CTGraphicalObjectFrame shape, XSLFSheet sheet){ super(shape, sheet); CTGraphicalObjectData god = shape.getGraphic().getGraphicData(); XmlCursor xc = god.newCursor(); try { if (!xc.toChild(XSLFRelation.NS_DRAWINGML, "tbl")) { throw new IllegalStateException("a:tbl element was not found in\n " + god); } XmlObject xo = xc.getObject(); // Pesky XmlBeans bug - see Bugzilla #49934 // it never happens when using the full ooxml-schemas jar but may happen with the abridged poi-ooxml-schemas if (xo instanceof XmlAnyTypeImpl){ String errStr = "Schemas (*.xsb) for CTTable can't be loaded - usually this happens when OSGI " + "loading is used and the thread context classloader has no reference to " + "the xmlbeans classes" ; throw new IllegalStateException(errStr); } _table = (CTTable)xo; } finally { xc.dispose(); } _rows = new ArrayList<>(_table.sizeOfTrArray()); for(CTTableRow row : _table.getTrList()) { _rows.add(new XSLFTableRow(row, this)); } updateRowColIndexes(); }
/** * Assign a DrawingML chart to the graphic frame. */ protected void setChart(XSSFChart chart, String relId) { CTGraphicalObjectData data = graphicFrame.getGraphic().addNewGraphicData(); appendChartElement(data, relId); chart.setGraphicFrame(this); return; }
CTGraphicalObjectData graphicData = graphic.getGraphicData(); CTPicture pic = getCTPictures(graphicData).get(0);
.append("\"/></a:xfrm><a:prstGeom prst=\"rect\"><a:avLst/></a:prstGeom></pic:spPr></pic:pic></a:graphicData></a:graphic>") .toString(); inline.addNewGraphic().addNewGraphicData(); try { XmlToken xmlToken = XmlToken.Factory.parse(picXml);
private static String getUri(CTGraphicalObjectFrame shape) { final CTGraphicalObject g = shape.getGraphic(); if (g == null) { return null; } CTGraphicalObjectData gd = g.getGraphicData(); return (gd == null) ? null : gd.getUri(); }
static CTGraphicalObjectFrame prototype(int shapeId){ CTGraphicalObjectFrame frame = CTGraphicalObjectFrame.Factory.newInstance(); CTGraphicalObjectFrameNonVisual nvGr = frame.addNewNvGraphicFramePr(); CTNonVisualDrawingProps cnv = nvGr.addNewCNvPr(); cnv.setName("Table " + shapeId); cnv.setId(shapeId + 1); nvGr.addNewCNvGraphicFramePr().addNewGraphicFrameLocks().setNoGrp(true); nvGr.addNewNvPr(); frame.addNewXfrm(); CTGraphicalObjectData gr = frame.addNewGraphic().addNewGraphicData(); XmlCursor cursor = gr.newCursor(); cursor.toNextToken(); cursor.beginElement(new QName("http://schemas.openxmlformats.org/drawingml/2006/main", "tbl")); cursor.beginElement(new QName("http://schemas.openxmlformats.org/drawingml/2006/main", "tblPr")); cursor.toNextToken(); cursor.beginElement(new QName("http://schemas.openxmlformats.org/drawingml/2006/main", "tblGrid")); cursor.dispose(); gr.setUri(TABLE_URI); return frame; }
/** * Construct a new XSSFGraphicFrame object. * * @param drawing the XSSFDrawing that owns this frame * @param ctGraphicFrame the XML bean that stores this frame content */ protected XSSFGraphicFrame(XSSFDrawing drawing, CTGraphicalObjectFrame ctGraphicFrame) { this.drawing = drawing; // protected field on XSSFShape this.graphicFrame = ctGraphicFrame; // TODO: there may be a better way to delegate this CTGraphicalObjectData graphicData = graphicFrame.getGraphic().getGraphicData(); if (graphicData != null) { NodeList nodes = graphicData.getDomNode().getChildNodes(); for (int i = 0; i < nodes.getLength(); i++) { final Node node = nodes.item(i); // if the frame references a chart, associate the chart with this instance if (node.getNodeName().equals("c:chart")) { // this better succeed or the document is invalid POIXMLDocumentPart relation = drawing.getRelationById(node.getAttributes().getNamedItem("r:id").getNodeValue()); // Do XWPF charts need similar treatment? if (relation instanceof XSSFChart) { ((XSSFChart) relation).setGraphicFrame(this); } } } } }
static CTGraphicalObjectFrame prototype(int shapeId){ CTGraphicalObjectFrame frame = CTGraphicalObjectFrame.Factory.newInstance(); CTGraphicalObjectFrameNonVisual nvGr = frame.addNewNvGraphicFramePr(); CTNonVisualDrawingProps cnv = nvGr.addNewCNvPr(); cnv.setName("Table " + shapeId); cnv.setId(shapeId); nvGr.addNewCNvGraphicFramePr().addNewGraphicFrameLocks().setNoGrp(true); nvGr.addNewNvPr(); frame.addNewXfrm(); CTGraphicalObjectData gr = frame.addNewGraphic().addNewGraphicData(); XmlCursor grCur = gr.newCursor(); grCur.toNextToken(); grCur.beginElement(new QName(XSLFRelation.NS_DRAWINGML, "tbl")); CTTable tbl = CTTable.Factory.newInstance(); tbl.addNewTblPr(); tbl.addNewTblGrid(); XmlCursor tblCur = tbl.newCursor(); tblCur.moveXmlContents(grCur); tblCur.dispose(); grCur.dispose(); gr.setUri(TABLE_URI); return frame; }
static XSLFGraphicFrame create(CTGraphicalObjectFrame shape, XSLFSheet sheet){ String uri = shape.getGraphic().getGraphicData().getUri(); if(XSLFTable.TABLE_URI.equals(uri)){ return new XSLFTable(shape, sheet); } else { return new XSLFGraphicFrame(shape, sheet); } }
+ " </a:graphicData>" + "</a:graphic>"; inline.addNewGraphic().addNewGraphicData(); XmlToken xmlToken = null; xmlToken = XmlToken.Factory.parse(picXml);
@Override void copy(XSLFShape sh){ super.copy(sh); CTGraphicalObjectData data = ((CTGraphicalObjectFrame)getXmlObject()).getGraphic().getGraphicData(); String uri = data.getUri(); if(uri.equals("http://schemas.openxmlformats.org/drawingml/2006/diagram")){ copyDiagram(data, (XSLFGraphicFrame)sh); } if(uri.equals("http://schemas.openxmlformats.org/drawingml/2006/chart")){ copyChart(data, (XSLFGraphicFrame)sh); } else { // TODO support other types of objects } }
inline.addNewGraphic().addNewGraphicData(); XmlToken xmlToken = null; try {