Join
Sign in
Search Options
Search Everything
Search Development Tools
Home
Blog
Resources
Forums
About Open XML
More ...
Home
»
Forums
»
Development Tools
»
.Net
»
XML paragraph code to an existing word docx file using open xml sdk 2.0
Re: XML paragraph code to an existing word docx file using open xml sdk 2.0
Development Tools
Discussions about working with Open XML using a wide range of development tools
Get this RSS feed
Details
1
Reply
1
Subscriber
Posted
over 2 years ago
Options
Subscribe via RSS
Share this
.Net
XML paragraph code to an existing word docx file using open xml sdk 2.0
rated by 0 users
This post has
1 Reply |
1
Follower
dotnetcoder2010
20
Posted by
dotnetcoder2010
on
Wed, Jul 14 2010 10:48 AM
rated by 0 users
Post Points: 20
XML paragraph code to an existing word docx file using open xml sdk 2.0
How to add a XML paragraph code to an existing word docx file using open xml sdk 2.0 in .net
<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
<w:pPr>
<w:jc w:val="left" />
</w:pPr>
<w:r>
<w:rPr>
<w:color w:val="auto" />
<w:b />
<w:rFonts w:ascii="Arial" w:hAnsi="Arial" w:cs="Arial" />
<w:sz w:val="28" />
</w:rPr>
<w:t>Hello World</w:t>
</w:r>
</w:p>
can it be done using AddCustomXmlPart or AddNewPart<CustomXmlPart>()
Regards
Intergen
2610
Posted by
Intergen
on
Thu, Jul 15 2010 6:02 PM
rated by 0 users
Post Points: 5
Re: XML paragraph code to an existing word docx file using open xml sdk 2.0
This code should do what you're wanting:
/// <summary>
/// Add a paragraph with the given <param name="text"/> to the <param name="docName"/>
/// </summary>
/// <param name="docName">Name of the document.</param>
/// <param name="text">The text to insert into the document.</param>
public static void AddParagraphWordprocessingDocumentWithText(string docName, string text)
{
// Open the Wordprocessing document.
using (WordprocessingDocument wordprocessingDocument = WordprocessingDocument.Open(docName, true))
{
Text docText = new Text(text);
Run run = new Run(docText);
Paragraph paragraph = new Paragraph(run);
wordprocessingDocument.MainDocumentPart.Document.Body.Append(paragraph);
// Save changes to the main document part.
wordprocessingDocument.MainDocumentPart.Document.Save();
}
}
Page 1 of 1 (2 items)