Quantcast
Channel: Open XML Format SDK forum
Viewing all articles
Browse latest Browse all 1288

Convert Word Processing Document to DOCX file

$
0
0

Hi,

Since I am new to this OpenXML, and as I am working on populating the OpenXML document programmatically using Open XML Power tools utility class as mentioned below, the objective of the is to search for the tag and replace it with value, and save the document as docx so that this file can be used for further processing.

Please help me in converting Word Processing Document back to docx file after replacing the text.

/***********************BEGIN OF CODE**************************************/

var byteArray = File.ReadAllBytes("Sample.docx");

using (var memoryStream = new MemoryStream())
 {
   memoryStream.Write(byteArray, 0, byteArray.Length);

   using (var wordDoc = WordprocessingDocument.Open(memoryStream, true))
    {
      //This SearchAndReplace is utility class from OpenXMLPower Tools returns WordprocessingDocument after replacing the  text in the Word Processing Document
      //And the function signature is  WordprocessingDocument SearchAndReplace(WordprocessingDocument wordDoc, string search, string replace, bool matchCase)
      var processedDoc = TextReplacer.SearchAndReplace(wordDoc, "«FullName»", "George Smith", true);

      //I need to know how to convert this above processedDoc(of type WordprocessingDocument) to back to docx file, so that I can use it for futher processing.
    }
 }

/**********************************END OF CODE*****************************/

FORMAT OF SAMPLE.DOCX

«FullName»,                                        

«CusStreet1», «CusStreet2»,

«CusCity»,«CusState»,«CusZip»,

Date: «DateToday»,

«ADDTEXT»,

/******************END OF FILE***************************/

Thanks in Advance.


Viewing all articles
Browse latest Browse all 1288

Latest Images

Trending Articles



Latest Images