Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6692941
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:55:32+00:00 2026-05-26T05:55:32+00:00

I have a Microsoft Word Document (docx) and I use Open XML SDK 2.0

  • 0

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 to the document.
For this I typed in simple text like [[place holder 1]] in the points where my program should replace the placeholders with its database values.

Unfortunately the XML output is in some kind of mess. E.g. I have a table with two neighboring cells, which shouldn’t distinguish apart from its placeholder. But one of the placeholders is split
into several runs.

[[good place holder]]

<w:tc xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:tcPr>
    <w:tcW w:w="1798" w:type="dxa" />
    <w:shd w:val="clear" w:color="auto" w:fill="auto" />
  </w:tcPr>
  <w:p w:rsidRPr="008C2E16" w:rsidR="001F54BF" w:rsidP="000D7B67" w:rsidRDefault="0009453E">
    <w:pPr>
      <w:spacing w:after="0" w:line="240" w:lineRule="auto" />
      <w:rPr>
        <w:rFonts w:cstheme="minorHAnsi" />
        <w:sz w:val="20" />
        <w:szCs w:val="20" />
      </w:rPr>
    </w:pPr>
    <w:r w:rsidRPr="0009453E">
      <w:rPr>
        <w:rFonts w:cstheme="minorHAnsi" />
        <w:sz w:val="20" />
        <w:szCs w:val="20" />
      </w:rPr>
      <w:t>[[good place holder]]</w:t>
    </w:r>
  </w:p>
</w:tc>

versus [[bad place holder]]

<w:tc xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main">
  <w:tcPr>
    <w:tcW w:w="1799" w:type="dxa" />
    <w:shd w:val="clear" w:color="auto" w:fill="auto" />
  </w:tcPr>
  <w:p w:rsidRPr="008C2E16" w:rsidR="001F54BF" w:rsidP="000D7B67" w:rsidRDefault="00EA211A">
    <w:pPr>
      <w:spacing w:after="0" w:line="240" w:lineRule="auto" />
      <w:rPr>
        <w:rFonts w:cstheme="minorHAnsi" />
        <w:sz w:val="20" />
        <w:szCs w:val="20" />
      </w:rPr>
    </w:pPr>
    <w:r w:rsidRPr="00EA211A">
      <w:rPr>
        <w:rFonts w:cstheme="minorHAnsi" />
        <w:sz w:val="20" />
        <w:szCs w:val="20" />
      </w:rPr>
      <w:t>[[</w:t>
    </w:r>
    <w:proofErr w:type="spellStart" />
    <w:r w:rsidRPr="00EA211A">
      <w:rPr>
        <w:rFonts w:cstheme="minorHAnsi" />
        <w:sz w:val="20" />
        <w:szCs w:val="20" />
      </w:rPr>
      <w:t>bad</w:t>
    </w:r>
    <w:proofErr w:type="spellEnd" />
    <w:r w:rsidRPr="00EA211A">
      <w:rPr>
        <w:rFonts w:cstheme="minorHAnsi" />
        <w:sz w:val="20" />
        <w:szCs w:val="20" />
      </w:rPr>
      <w:t xml:space="preserve"> place holder]]</w:t>
    </w:r>
  </w:p>
</w:tc>

Is there any possibility to let Microsoft Word clean up my document, so that all place holders are good to identify in the generated XML?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T05:55:33+00:00Added an answer on May 26, 2026 at 5:55 am

    I have found a solution: the Open XML PowerTools Markup Simplifier.

    I followed the steps described at http://ericwhite.com/blog/2011/03/09/getting-started-with-open-xml-powertools-markup-simplifier/, but it didn’t work 1:1 (maybe because it is now version 2.2 of Power Tools?). So, I compiled PowerTools 2.2 in "Release" mode and made a reference to the OpenXmlPowerTools.dll in my TestMarkupSimplifier.csproj. In the Program.cs I only changed the path to my DOCX file.
    I ran the program once and my document seems to be fairly clean now.

    Code quoted from Eric’s blog in the link above:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using OpenXmlPowerTools;
    using DocumentFormat.OpenXml.Packaging;
    
    class Program
    {
        static void Main(string[] args)
        {
            using (WordprocessingDocument doc = WordprocessingDocument.Open("Test.docx", true))
            {
                SimplifyMarkupSettings settings = new SimplifyMarkupSettings
                {
                    RemoveComments = true,
                    RemoveContentControls = true,
                    RemoveEndAndFootNotes = true,
                    RemoveFieldCodes = false,
                    RemoveLastRenderedPageBreak = true,
                    RemovePermissions = true,
                    RemoveProof = true,
                    RemoveRsidInfo = true,
                    RemoveSmartTags = true,
                    RemoveSoftHyphens = true,
                    ReplaceTabsWithSpaces = true,
                };
                MarkupSimplifier.SimplifyMarkup(doc, settings);
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have quite big document in html format that generated from Microsoft Word. It
I have some C# automation code which does interesting things with Microsoft.Office.Interop.Word.Document objects. The
I have automated word document creation from templates using the Microsoft Word 12.0 Object
I have a requirement to open a Microsoft Word document using Silverlight 3. The
I have been given two different Microsoft Word document that my virus scanner has
I have Microsoft Word template that I automated filling it's fields from my application,
I have a very simple Office utility question. Open Microsoft word (2003 or 2007),
I need an option from within PHP to Manipulate .docx (Microsoft Office 2007) document.
I have this code: Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application(); object nullobj = System.Reflection.Missing.Value; object
I have a word document I want to parse with C#. There are plenty

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.