This project has moved and is read-only. For the latest updates, please go here.

Determine If Word Style Is A Table

Dec 8, 2015 at 2:02 AM
I need to parse several .docx files. The way I need to parse these documents is from a top-down approach where when I come across a certain "object" ( word table, picture, graphic, equation, ... ) do something specific.

I wrote the following code. Given a document this code will navigate through all the paragraph instances in-order and print out the styles. I noticed that some of these styles ( "Normal" in this case ) are actually associated with a table object.
using Novacode;
using System;

namespace resrap
{
    internal class Program
    {
        private static void Main( string[] args )
        {
            using ( DocX document = DocX.Load( args[0] ) )
            {
                foreach ( var paraType in document.Paragraphs )
                {
                    Console.WriteLine( paraType.StyleName );
                }
            }
        }
    }
}
Is there a way for me to determine if a given paragraph is associated with a Word table? I know how to grab all the tables in the document but since I need to parse the document in order ( and later put the parsed contents in order of sorts ) using something like this isn't that helpful since I don't know where these tables are actually located within the document.
using Novacode;
using System;

namespace resrap
{
    internal class Program
    {
        private static void Main( string[] args )
        {
            using ( DocX document = DocX.Load( args[0] ) )
            {
                for ( int index = 0; index < document.Tables.Count; index++ )
                {
                    var table = document.Tables[index];
                    // do something with table
                }
            }
        }
    }
}
I am unsure if my approach I have ( first code example ) is the way to do this but I will continue to figure this out while I wait for any possible guidance/tips.

Thanks for reading and any feedback.
Dec 8, 2015 at 3:09 AM
It appears I can use the ParentContainer property of the Paragraph to check if the value is Cell. Going to try it out.