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