How can I programmatically walk through all of the elements of a word document (in order)? RRS feed

  • Question

  • I'm trying to write a simple program that converts a Word document to a custom format, and shows indentation.  The closest thing that meets my needs is converting the document to HTML format but I don't have code for that.

    I care about: Headings, Tables, Images, and Paragraphs.

    So I want to start at the front of the document and each of these items "IN ORDER".
    So far I see there are collections of objects, Tables, Image, Paragraphs but I don't (yet) know how to order these things.  For example, heading, paragraph, table, heading, heading, paragraph, image, table, paragraph.

    So if I have something like this (I'm including the styles in {stylename})
    {Heading 1}Introduction
    This is a nice document.
    {Heading 2}Audience
    This has a nice audience.
    {Heading 1}System Summary
    {Normal} Some stuff.
    {Normal} Some stuff2.
    {Heading 2}Important Topics
    TABLE GOES HERE (has several paragraphs)
    {Heading 1}Detailed Notes
    {Normal}more stuff

    I want to produce something like this:
    * Introduction
    This is a nice document.
    ** Audience
    This has a nice audience.
    * System Summary
    Some stuff.
    Some stuff2.
    ** Important Topics
    Messed up table goes here... :-)
    * Detailed Notes
    more stuff

    I'm currently looping over all of the paragraphs in the document and when I get the style that begins with "Heading ", I know to print a heading indicator.

    The problem is I don't (yet) know how to handle tables, or pictures.
    I don't need to embed pictures I can just say [pict would go here], but
    I would like to know how to identify the tables.

    I know there are utilities to convert word to other formats but I'm interested in learning how word works as much as doing this conversion.
    • Moved by Liliane Teng Wednesday, June 1, 2011 2:14 AM (From:Visual Basic General)
    Wednesday, May 25, 2011 8:22 PM

All replies