Simplify/ Clean up XML of a DOCX word document

前端 未结 4 440
甜味超标
甜味超标 2021-02-04 02:40

I have a Microsoft Word Document (docx) and I use Open XML SDK 2.0 Productivity Tool to generate C# code from it.

I want to programmatically insert some database values

4条回答
  •  无人共我
    2021-02-04 03:18

    You need to get rid of the Rsid information. According to this page Rsid information

    enables merging of two documents that have forked.

    You need to install in order to run the sample code below. The easiest way to do that is to run the following in the Package Manager Console

    Install-Package OpenXmlPowerTools
    

    Then you will be all set to run the following code. (Assuming that you already have a "Test.docx" file added to your document. If you are using Visual Studio, you need to make sure that you have a copy of the file in either the Debug or Release folder according to your build mode.)

    //Sample code to remove Rsid information from a "Test.docx" document
    
     using (WordprocessingDocument doc = WordprocessingDocument.Open("Test.docx", true))
            {
                SimplifyMarkupSettings settings = new SimplifyMarkupSettings
                {  
                    RemoveRsidInfo = true 
                };
                MarkupSimplifier.SimplifyMarkup(doc, settings);
            }
    

    This will remove Rsid information that may get in the way in the process of manipulating Word files.

提交回复
热议问题