Guest User

Untitled

a guest
Oct 23rd, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. static void Main(string[] args)
  2. {
  3. string destinationWordFile = @"C:UsersTestingModified Files1216085_01012013.docx";
  4. using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(destinationWordFile, true, new OpenSettings { AutoSave = true }))
  5. {
  6. OpenXmlWdProcessing.RunProperties rp = new OpenXmlWdProcessing.RunProperties();
  7. MainDocumentPart mainPart = wordDoc.MainDocumentPart;
  8. var invoiceDocument = wordDoc.MainDocumentPart.Document;
  9. var po = (from body in invoiceDocument.Body
  10. where body.InnerText.Contains("PO:")
  11. select body).FirstOrDefault();
  12. string poInnerXml = po.InnerXml;
  13. string modifiedXML = poInnerXml.Remove(poInnerXml.IndexOf("w:w=""), 10);
  14. po.InnerXml.Remove(0);
  15. po.InnerXml.Insert(0,modifiedXML);
  16. mainPart.Document.Save();
  17. }
  18.  
  19. <w:pPr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  20. <w:pStyle w:val="Normal" />
  21. <w:framePr w:w="516" w:x="6881" w:y="7175" />
  22. <w:widowControl w:val="off" />
  23. <w:autoSpaceDE w:val="off" />
  24. <w:autoSpaceDN w:val="off" />
  25. <w:spacing w:before="0" w:after="0" w:line="179" w:lineRule="exact" />
  26. <w:ind w:left="0" w:right="0" w:first-line="0" />
  27. <w:jc w:val="left" />
  28. <w:rPr>
  29. <w:rFonts w:ascii="AATWWN+Helvetica" />
  30. <w:color w:val="000000" />
  31. <w:sz w:val="16" />
  32. </w:rPr>
  33. </w:pPr>
  34. <w:r xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  35. <w:rPr>
  36. <w:rFonts w:ascii="AATWWN+Helvetica" />
  37. <w:color w:val="000000" />
  38. <w:sz w:val="16" />
  39. </w:rPr>
  40. <w:t>PO: 111111111111</w:t>
  41. </w:r>
  42.  
  43. //Get all paragraphs in the document
  44. IEnumerable<Paragraph> paragraphs = doc.MainDocumentPart.Document.Body.OfType<Paragraph>();
  45. foreach (Paragraph paragraph in paragraphs)
  46. {
  47. FrameProperties framePr = paragraph.OfType<FrameProperties>().FirstOrDefault();
  48. framePr.Width = null;
  49. }
  50.  
  51. //paragraph is the Paragraph object that needs to be processed.
  52.  
  53. FrameProperties frameProperties = pTag.Descendants<FrameProperties>().FirstOrDefault();
  54. if (frameProperties != null)
  55. {
  56. frameProperties.Width = null; //give string value if you want to set one say "516"
  57. // To set/remove height attribute use this.
  58. frameProperties.Height = null;
  59. //To Remove frame properties itself from paragraph
  60. frameProperties.Remove();
  61. }
  62.  
  63. //package is the object of WordProcessingDocument
  64. package.MainDocumentPart.Document.Save();
Add Comment
Please, Sign In to add comment