/** * Assign a DrawingML chart to the graphic frame. */ internal void SetChart(XSSFChart chart, String relId) { CT_GraphicalObjectData data = graphicFrame.graphic.AddNewGraphicData(); AppendChartElement(data, relId); chart.SetGraphicFrame(this); return; }
/** * The low level code to insert {@code <c:chart>} tag into * {@code<a:graphicData>}. * * Here is the schema (ECMA-376): * <pre> * {@code * <complexType name="CT_GraphicalObjectData"> * <sequence> * <any minOccurs="0" maxOccurs="unbounded" ProcessContents="strict"/> * </sequence> * <attribute name="uri" type="xsd:token"/> * </complexType> * } * </pre> */ private void AppendChartElement(CT_GraphicalObjectData data, String id) { String r_namespaceUri = ST_RelationshipId.NamespaceURI; String c_namespaceUri = XSSFDrawing.NAMESPACE_C; //XmlCursor cursor = data.newCursor(); //cursor.ToNextToken(); //cursor.beginElement(new QName(c_namespaceUri, "chart", "c")); //cursor.insertAttributeWithValue(new QName(r_namespaceUri, "id", "r"), id); //cursor.dispose(); //data.SetUri(c_namespaceUri); }
private void GetPictures(CT_GraphicalObjectData god, List <NPOI.OpenXmlFormats.Dml.Picture.CT_Picture> pictures) { XmlSerializer xmlSerializer = new XmlSerializer(typeof(NPOI.OpenXmlFormats.Dml.Picture.CT_Picture)); foreach (XmlNode xmlNode in god.Any) { StringReader stringReader = new StringReader(xmlNode.OuterXml); NPOI.OpenXmlFormats.Dml.Picture.CT_Picture ctPicture = xmlSerializer.Deserialize(XmlReader.Create((TextReader)stringReader)) as NPOI.OpenXmlFormats.Dml.Picture.CT_Picture; pictures.Add(ctPicture); } }
private void GetPictures(CT_GraphicalObjectData god, List <NPOI.OpenXmlFormats.Dml.Picture.CT_Picture> pictures) { XmlSerializer xmlse = new XmlSerializer(typeof(NPOI.OpenXmlFormats.Dml.Picture.CT_Picture)); foreach (string el in god.Any) { System.IO.StringReader stringReader = new System.IO.StringReader(el); NPOI.OpenXmlFormats.Dml.Picture.CT_Picture pict = xmlse.Deserialize(System.Xml.XmlReader.Create(stringReader)) as NPOI.OpenXmlFormats.Dml.Picture.CT_Picture; pictures.Add(pict); } }
/// <summary> /// The low level code to insert <code><c:chart></code> tag into <code><a:graphicData></code> /// </summary> /// <param name="data"></param> /// <param name="id"></param> /// <example> /// <complexType name="CT_GraphicalObjectData"> /// <sequence> /// <any minOccurs="0" maxOccurs="unbounded" ProcessContents="strict"/> /// </sequence> /// <attribute name="uri" type="xsd:token"/> /// </complexType> /// </example> private void AppendChartElement(CT_GraphicalObjectData data, String id) { String r_namespaceUri = ST_RelationshipId.NamespaceURI; String c_namespaceUri = XSSFDrawing.NAMESPACE_C; //AppendChartElement string el = string.Format("<c:chart xmlns:c=\"{1}\" xmlns:r=\"{2}\" r:id=\"{0}\"/>", id, c_namespaceUri, r_namespaceUri); data.AddChartElement(el); //XmlCursor cursor = data.newCursor(); //cursor.ToNextToken(); //cursor.beginElement(new QName(c_namespaceUri, "chart", "c")); //cursor.insertAttributeWithValue(new QName(r_namespaceUri, "id", "r"), id); //cursor.dispose(); data.uri = c_namespaceUri; //throw new NotImplementedException(); }
/** * Adds a picture to the run. This method handles * attaching the picture data to the overall file. * * @see NPOI.XWPF.UserModel.Document#PICTURE_TYPE_EMF * @see NPOI.XWPF.UserModel.Document#PICTURE_TYPE_WMF * @see NPOI.XWPF.UserModel.Document#PICTURE_TYPE_PICT * @see NPOI.XWPF.UserModel.Document#PICTURE_TYPE_JPEG * @see NPOI.XWPF.UserModel.Document#PICTURE_TYPE_PNG * @see NPOI.XWPF.UserModel.Document#PICTURE_TYPE_DIB * * @param pictureData The raw picture data * @param pictureType The type of the picture, eg {@link Document#PICTURE_TYPE_JPEG} * @param width width in EMUs. To convert to / from points use {@link org.apache.poi.util.Units} * @param height height in EMUs. To convert to / from points use {@link org.apache.poi.util.Units} * @throws NPOI.Openxml4j.exceptions.InvalidFormatException * @throws IOException */ public XWPFPicture AddPicture(Stream pictureData, int pictureType, String filename, int width, int height) { XWPFDocument doc = paragraph.GetDocument(); // Add the picture + relationship String relationId = doc.AddPictureData(pictureData, pictureType); XWPFPictureData picData = (XWPFPictureData)doc.GetRelationById(relationId); // Create the Drawing entry for it try { NPOI.OpenXmlFormats.Wordprocessing.CT_Drawing Drawing = run.AddNewDrawing(); CT_Inline inline = Drawing.AddNewInline(); // Do the fiddly namespace bits on the inline // (We need full control of what goes where and as what) //CT_GraphicalObject tmp = new CT_GraphicalObject(); //String xml = // "<a:graphic xmlns:a=\"" + "http://schemas.openxmlformats.org/drawingml/2006/main" + "\">" + // "<a:graphicData uri=\"" + "http://schemas.openxmlformats.org/drawingml/2006/picture" + "\">" + // "<pic:pic xmlns:pic=\"" + "http://schemas.openxmlformats.org/drawingml/2006/picture" + "\" />" + // "</a:graphicData>" + // "</a:graphic>"; //inline.Set((xml)); XmlDocument xmlDoc = new XmlDocument(); XmlElement el = xmlDoc.CreateElement("pic", "pic", "http://schemas.openxmlformats.org/drawingml/2006/picture"); inline.graphic = new CT_GraphicalObject(); inline.graphic.graphicData = new CT_GraphicalObjectData(); inline.graphic.graphicData.AddPicElement((XmlElement)el.Clone()); // Setup the inline inline.distT = (0); inline.distR = (0); inline.distB = (0); inline.distL = (0); CT_NonVisualDrawingProps docPr = inline.AddNewDocPr(); long id = GetParagraph().GetDocument().GetDrawingIdManager().ReserveNew(); docPr.id = (uint)(id); /* This name is not visible in Word 2010 anywhere. */ docPr.name = ("Drawing " + id); docPr.descr = (filename); CT_PositiveSize2D extent = inline.AddNewExtent(); extent.cx = (width); extent.cy = (height); // Grab the picture object CT_GraphicalObject graphic = inline.graphic; CT_GraphicalObjectData graphicData = graphic.graphicData; NPOI.OpenXmlFormats.Dml.Picture.CT_Picture pic = GetCTPictures(graphicData)[(0)]; // Set it up NPOI.OpenXmlFormats.Dml.Picture.CT_PictureNonVisual nvPicPr = pic.AddNewNvPicPr(); CT_NonVisualDrawingProps cNvPr = nvPicPr.AddNewCNvPr(); /* use "0" for the id. See ECM-576, 20.2.2.3 */ cNvPr.id = (0); /* This name is not visible in Word 2010 anywhere */ cNvPr.name = ("Picture " + id); cNvPr.descr = (filename); CT_NonVisualPictureProperties cNvPicPr = nvPicPr.AddNewCNvPicPr(); cNvPicPr.AddNewPicLocks().noChangeAspect = true; CT_BlipFillProperties blipFill = pic.AddNewBlipFill(); CT_Blip blip = blipFill.AddNewBlip(); blip.embed = (picData.GetPackageRelationship().Id); blipFill.AddNewStretch().AddNewFillRect(); CT_ShapeProperties spPr = pic.AddNewSpPr(); CT_Transform2D xfrm = spPr.AddNewXfrm(); CT_Point2D off = xfrm.AddNewOff(); off.x = (0); off.y = (0); CT_PositiveSize2D ext = xfrm.AddNewExt(); ext.cx = (width); ext.cy = (height); CT_PresetGeometry2D prstGeom = spPr.AddNewPrstGeom(); prstGeom.prst = (ST_ShapeType.rect); prstGeom.AddNewAvLst(); // Finish up XWPFPicture xwpfPicture = new XWPFPicture(pic, this); pictures.Add(xwpfPicture); return(xwpfPicture); } catch (Exception e) { throw new InvalidOperationException("", e); } }
private void AppendChartElement(CT_GraphicalObjectData data, string id) { string namespaceUri = ST_RelationshipId.NamespaceURI; }