/// <summary> /// word图片对应处理 /// </summary> /// <param name="ctr"></param> /// <param name="picInfoList"></param> /// <returns></returns> public StringBuilder DrawingHandle(CT_R ctr, List <PicInfo> picInfoList) { var sb = new StringBuilder(); var drawingList = ctr.GetDrawingList(); foreach (var drawing in drawingList) { var a = drawing.GetInlineList(); foreach (var a1 in a) { var anyList = a1.graphic.graphicData.Any; foreach (var any1 in anyList) { var pictures = picInfoList .FirstOrDefault(x => any1.IndexOf("a:blip r:embed=\"" + x.Id + "\"", StringComparison.Ordinal) > -1); if (pictures != null && !string.IsNullOrWhiteSpace(pictures.Url)) { sb.Append($@"<img src='{pictures.Url}' />"); } } } } return(sb); }
public XWPFRun(CT_R r, XWPFParagraph p) { this.run = r; this.paragraph = p; IList <CT_Drawing> drawingList = r.GetDrawingList(); foreach (CT_Drawing ctDrawing in (IEnumerable <CT_Drawing>)drawingList) { foreach (CT_Anchor anchor in ctDrawing.GetAnchorList()) { if (anchor.docPr != null) { this.GetDocument().GetDrawingIdManager().Reserve((long)anchor.docPr.id); } } foreach (CT_Inline inline in ctDrawing.GetInlineList()) { if (inline.docPr != null) { this.GetDocument().GetDrawingIdManager().Reserve((long)inline.docPr.id); } } } StringBuilder stringBuilder = new StringBuilder(); List <object> objectList = new List <object>(); foreach (NPOI.OpenXmlFormats.Wordprocessing.CT_Picture pict in (IEnumerable <NPOI.OpenXmlFormats.Wordprocessing.CT_Picture>)r.GetPictList()) { objectList.Add((object)pict); } foreach (CT_Drawing ctDrawing in (IEnumerable <CT_Drawing>)drawingList) { objectList.Add((object)ctDrawing); } foreach (object obj in objectList) { ; } this.pictureText = stringBuilder.ToString(); this.pictures = new List <XWPFPicture>(); foreach (object o in objectList) { foreach (NPOI.OpenXmlFormats.Dml.Picture.CT_Picture ctPicture in this.GetCTPictures(o)) { this.pictures.Add(new XWPFPicture(ctPicture, this)); } } }
/** * @param r the CT_R bean which holds the run.attributes * @param p the parent paragraph */ public XWPFRun(CT_R r, IRunBody p) { this.run = r; this.parent = p; /** * reserve already occupied Drawing ids, so reserving new ids later will * not corrupt the document */ IList <CT_Drawing> drawingList = r.GetDrawingList(); foreach (CT_Drawing ctDrawing in drawingList) { List <CT_Anchor> anchorList = ctDrawing.GetAnchorList(); foreach (CT_Anchor anchor in anchorList) { if (anchor.docPr != null) { this.Document.DrawingIdManager.Reserve(anchor.docPr.id); } } List <CT_Inline> inlineList = ctDrawing.GetInlineList(); foreach (CT_Inline inline in inlineList) { if (inline.docPr != null) { this.Document.DrawingIdManager.Reserve(inline.docPr.id); } } } //// Look for any text in any of our pictures or Drawings StringBuilder text = new StringBuilder(); List <object> pictTextObjs = new List <object>(); foreach (CT_Picture pic in r.GetPictList()) { pictTextObjs.Add(pic); } foreach (CT_Drawing draw in drawingList) { pictTextObjs.Add(draw); } //foreach (object o in pictTextObjs) //{ //todo:: imlement this //XmlObject[] t = o.SelectPath("declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' .//w:t"); //for (int m = 0; m < t.Length; m++) //{ // NodeList kids = t[m].DomNode.ChildNodes; // for (int n = 0; n < kids.Length; n++) // { // if (kids.Item(n) is Text) // { // if (text.Length > 0) // text.Append("\n"); // text.Append(kids.Item(n).NodeValue); // } // } //} //} pictureText = text.ToString(); // Do we have any embedded pictures? // (They're a different CT_Picture, under the Drawingml namespace) pictures = new List <XWPFPicture>(); foreach (object o in pictTextObjs) { foreach (OpenXmlFormats.Dml.Picture.CT_Picture pict in GetCTPictures(o)) { XWPFPicture picture = new XWPFPicture(pict, this); pictures.Add(picture); } } }
/** * @param r the CT_R bean which holds the run.attributes * @param p the parent paragraph */ public XWPFRun(CT_R r, IRunBody p) { this.run = r; this.parent = p; /** * reserve already occupied Drawing ids, so reserving new ids later will * not corrupt the document */ IList<CT_Drawing> drawingList = r.GetDrawingList(); foreach (CT_Drawing ctDrawing in drawingList) { List<CT_Anchor> anchorList = ctDrawing.GetAnchorList(); foreach (CT_Anchor anchor in anchorList) { if (anchor.docPr != null) { this.Document.DrawingIdManager.Reserve(anchor.docPr.id); } } List<CT_Inline> inlineList = ctDrawing.GetInlineList(); foreach (CT_Inline inline in inlineList) { if (inline.docPr != null) { this.Document.DrawingIdManager.Reserve(inline.docPr.id); } } } //// Look for any text in any of our pictures or Drawings StringBuilder text = new StringBuilder(); List<object> pictTextObjs = new List<object>(); foreach (CT_Picture pic in r.GetPictList()) pictTextObjs.Add(pic); foreach (CT_Drawing draw in drawingList) pictTextObjs.Add(draw); //foreach (object o in pictTextObjs) //{ //todo:: imlement this //XmlObject[] t = o.SelectPath("declare namespace w='http://schemas.openxmlformats.org/wordprocessingml/2006/main' .//w:t"); //for (int m = 0; m < t.Length; m++) //{ // NodeList kids = t[m].DomNode.ChildNodes; // for (int n = 0; n < kids.Length; n++) // { // if (kids.Item(n) is Text) // { // if (text.Length > 0) // text.Append("\n"); // text.Append(kids.Item(n).NodeValue); // } // } //} //} pictureText = text.ToString(); // Do we have any embedded pictures? // (They're a different CT_Picture, under the Drawingml namespace) pictures = new List<XWPFPicture>(); foreach (object o in pictTextObjs) { foreach (OpenXmlFormats.Dml.Picture.CT_Picture pict in GetCTPictures(o)) { XWPFPicture picture = new XWPFPicture(pict, this); pictures.Add(picture); } } }