Word 2007 <w:t> Tags RRS feed

  • Question

  • I am writing a program that reads Word 2007 XML, finds custom tags I define (example: #Amount#) and replaces them with a value from a database. It is sort of a programmatic mail merge. My issue is this, I create a "template" document that might look like the following:


    Template Document Header


    Some text some text #Amount# some text some text



    When my program reads the XML in, it looks for #Amount# to replace, but the pound signs are being surrounded by text tags, like <w:t>#</w:t>, so my find is failing. Is there any way to prevent Word from cutting my text up?



    Monday, February 11, 2008 5:34 PM

All replies

  •  Did you ever receive a solution for this?  I have the same problem and it is frustrating.

    Monday, December 22, 2008 8:19 PM
  • It could be caused by the grammar and/or spell checking markers that Word adds.  If that is the problem, one workaround would be to to open the document in Word and, if you see the grammer or spell check markers (red and green squiggly underlines), right click on them and mark them as ignored.  That should condense the text back to the run you need to find.  A more involved solution would be to scan the Open XML document for the starting and ending grammar/spellcheck XML tags, remove them, and concatenate the text runs before and after each one, then do the replacements.  You can use the DocumentExplorer tool that comes with the Open XML SDK to browse the document structure to see how things are arranged and how you might go about implementing such a solution.  It's something I may need to look into for a project I'm working on but I haven't done it yet.


    • Proposed as answer by EWoodruff Monday, December 22, 2008 9:22 PM
    Monday, December 22, 2008 9:11 PM