2
votes

I am iterating through paragraphs in a word document using word interop API. So far i did not have a problem detecting different headings by using the style object. However now i have a situation that contents inside a table have the same style as those outside it. I need to figure out a way to understand when the paragraph in question is actually a table.

I have similar need to figure out when paragraph is actually an embedded image.

When i physically select a table or image in the word document i can see that tools section above format changes. When an image is selected it is "Picture tools" when a table is selected it is 'Table tools" and when a normal paragraph is selected the tools section does not show.

How can i detect this behavior using word interop API?

Thanks Sameer

1

1 Answers

3
votes

Though this post seems to be old, I came across this while searching for a similar problem while working on Office automation, hope this post will help to investigate and expand further.

While looping through paragraphs of a word document,

Paragraph.Range.Tables.Count provides a value indicating if the paragraph is inside a table or not.

Paragraph Outside table :  Paragraph.Range.Tables.Count = 0
Paragraph Inside  table :  Paragraph.Range.Tables.Count = 1 ( or above not checked )

To get end of table (last paragraph inside table)

                    :  Paragraph.Next().Range.Tables.Count == 0

(The above logic applies while using NetOffice assembly, which in-turn uses interop assemblies,hope this is applicable directly to word interop assembly also)