private static void ModifyWordParagraphTextContent(OXW.Paragraph paragraph, string txt) { if (null != paragraph) { OXW.Run run = paragraph.Descendants <OXW.Run>().FirstOrDefault(); if (null != run) { run = run.CloneNode(true) as OXW.Run; paragraph.RemoveAllChildren <OXW.Run>(); } else { run = new OXW.Run(); } OXW.Text text = run.Descendants <OXW.Text>().FirstOrDefault(); text = (null == text ? new OXW.Text() : text.CloneNode(true) as OXW.Text); run.RemoveAllChildren <OXW.Text>(); text.Text = txt; if (!string.IsNullOrEmpty(txt) && (char.IsWhiteSpace(txt[0]) || char.IsWhiteSpace(txt[txt.Length - 1]))) { text.Space = SpaceProcessingModeValues.Preserve; } run.Append(text); paragraph.Append(run); } }
public static IEnumerable <FixedDrawing> CreateFixedDrawingElements(this Word.Paragraph paragraph, IImageAccessor imageAccessor) { var drawings = paragraph .Descendants <Word.Drawing>() .Where(d => d.Anchor != null) .Select(d => d.Anchor.ToFixedDrawing(imageAccessor)) .ToArray(); return(drawings); }
private static string GetParagraphTextInTable(Paragraph p, string fullpagename, WordprocessingDocument doc, List<Blip> blips) { var sb = new StringBuilder(); sb.Append(GetStyledText(p)); foreach (Blip blip in p.Descendants<Blip>()) { OpenXmlPart imagePart = doc.MainDocumentPart.GetPartById(blip.Embed.Value); string fl = Path.GetFileName(imagePart.Uri.ToString()); sb.Append(string.Format("[image||{{UP({0})}}{1}]", fullpagename, fl)); blips.Add(blip); } return sb.ToString(); }