OpenXml entry-add text to a Word document, openxmlword

Source: Internet
Author: User

OpenXml entry-add text to a Word document, openxmlword

Use OpenXml to add text to Word documents. Each module has its own attributes and content. To set a style, declare the attribute object and Append the style to the attribute, append the attribute to the module, and the content in the module will have the style. This method appends content to the end of the file by default.

Code:

 

Using System; using System. collections. generic; using System. linq; using System. text; using System. threading. tasks; using DocumentFormat. openXml; using DocumentFormat. openXml. packaging; using DocumentFormat. openXml. wordprocessing; namespace AddStringToWord {public class Program {public static void Main (string [] args) {AddString ("Test.docx", "");} public static void AddString (string filePath, string str) {using (WordprocessingDocument doc = WordprocessingDocument. open (filePath, true) {Paragraph paragraph = new Paragraph (); Run run = new Run (); RunProperties runProperties = new RunProperties (); // attribute RunFonts fonts = new RunFonts () {EastAsia = "DFKai-SB"}; // set FontSize = new FontSize () {Val = "52 "}; // set the font size Color = new color () {Val = "red"}; // set the font style // Add the style to runProperties in the property. append (color); runProperties. append (size); runProperties. append (fonts); run. append (runProperties); run. append (new Text (str); paragraph. append (run); doc. mainDocumentPart. document. body. append (paragraph); doc. mainDocumentPart. document. save ();}}}}

As follows:


How to convert an Office Open XML document to a Word document 2003

If your Office version is 2007, open the docx file in WORD and save it as the doc file in WORD 2003.

If your Office version is 2003, you can download an Office 2007 compatibility package from Microsoft to open the docx file and save it as another file.

How to convert an XML document into readable text such as a Word document

You can use regular expressions to match and then save the matching set to the RPX image-text conversion software in Word. It's good. You can try it.
Hkgabate702011/7/27 23:52:04
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.