On including external text into Word 2003 document

| No Comments | No TrackBacks

Looks like everyone but I knows it. I stumbled at Mike Gunderloy's "Working with Microsoft Office 2003 Documents and Web Services" article at OfficeZealot.com illustrating how to use INCLUDETEXT field in Word 2003. Very nice feature! Here is how it looks like for XML nerd, newbie in Word.

INCLUDETEXT field allows to have updatable field in Word 2003 document, which content is included from another document. It's actually implementation of Insert/File feature. Word 2003 Pro edition even allows partial inclusion (via XPath selection) and XSL transformation before the inclusion. Cool. It's a pity looks like it works only in Pro edition.

Here is how it looks line in WordML:

<w:p>
  <w:fldSimple w:instr="INCLUDETEXT  
&quot;D:\\Temp\\books.xml&quot; \c XML 
\x /catalog/book[1]/title  \* MERGEFORMAT">
  <w:r>
    <w:t>Included content</w:t>
  </w:r>
  </w:fldSimple>
</w:p>
Well, not really XMLish, but anyway. w:instr contains field's instruction text. Above instruction means "include value of /catalog/book[1]/title element from D:\\Temp\\books.xml document". Nested w:r (or other run-level elements) holds included content. Word doesn't update fields authomatically, even during document loading. Updating should be done by user from the context menu (or it can be done in code). w:fldLock attribute can be used to prevent updating of the field.

It's text inclusion, not transclusion (when context info such as style is preserved). Inclusion of WordML elements actually works, but looks like styles and other metainformation isn't preserved, so basically you can for instance include first paragraph from another WordML doc, but without the style etc. Anyway, that's good idea to include code samples into a Word document this way, then you can modify code and onlly update fields in Word. Here is how XML samples could be included:

<w:fldSimple w:instr="INCLUDETEXT 
&quot;D:\\Temp\\books.xml&quot; \c PCText">
Without \c PCText XML will be included as XML and shown with graphical tags.

Related Blog Posts

No TrackBacks

TrackBack URL: http://www.tkachenko.com/cgi-bin/mt-tb.cgi/150

Leave a comment