Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void Main(string[] args)
- {
- string destinationWordFile = @"C:UsersTestingModified Files1216085_01012013.docx";
- using (WordprocessingDocument wordDoc = WordprocessingDocument.Open(destinationWordFile, true, new OpenSettings { AutoSave = true }))
- {
- OpenXmlWdProcessing.RunProperties rp = new OpenXmlWdProcessing.RunProperties();
- MainDocumentPart mainPart = wordDoc.MainDocumentPart;
- var invoiceDocument = wordDoc.MainDocumentPart.Document;
- var po = (from body in invoiceDocument.Body
- where body.InnerText.Contains("PO:")
- select body).FirstOrDefault();
- string poInnerXml = po.InnerXml;
- string modifiedXML = poInnerXml.Remove(poInnerXml.IndexOf("w:w=""), 10);
- po.InnerXml.Remove(0);
- po.InnerXml.Insert(0,modifiedXML);
- mainPart.Document.Save();
- }
- <w:pPr xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
- <w:pStyle w:val="Normal" />
- <w:framePr w:w="516" w:x="6881" w:y="7175" />
- <w:widowControl w:val="off" />
- <w:autoSpaceDE w:val="off" />
- <w:autoSpaceDN w:val="off" />
- <w:spacing w:before="0" w:after="0" w:line="179" w:lineRule="exact" />
- <w:ind w:left="0" w:right="0" w:first-line="0" />
- <w:jc w:val="left" />
- <w:rPr>
- <w:rFonts w:ascii="AATWWN+Helvetica" />
- <w:color w:val="000000" />
- <w:sz w:val="16" />
- </w:rPr>
- </w:pPr>
- <w:r xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
- <w:rPr>
- <w:rFonts w:ascii="AATWWN+Helvetica" />
- <w:color w:val="000000" />
- <w:sz w:val="16" />
- </w:rPr>
- <w:t>PO: 111111111111</w:t>
- </w:r>
- //Get all paragraphs in the document
- IEnumerable<Paragraph> paragraphs = doc.MainDocumentPart.Document.Body.OfType<Paragraph>();
- foreach (Paragraph paragraph in paragraphs)
- {
- FrameProperties framePr = paragraph.OfType<FrameProperties>().FirstOrDefault();
- framePr.Width = null;
- }
- //paragraph is the Paragraph object that needs to be processed.
- FrameProperties frameProperties = pTag.Descendants<FrameProperties>().FirstOrDefault();
- if (frameProperties != null)
- {
- frameProperties.Width = null; //give string value if you want to set one say "516"
- // To set/remove height attribute use this.
- frameProperties.Height = null;
- //To Remove frame properties itself from paragraph
- frameProperties.Remove();
- }
- //package is the object of WordProcessingDocument
- package.MainDocumentPart.Document.Save();
Add Comment
Please, Sign In to add comment