0

I have a document with a number of paragraphs, a table and then a few more paragraphs. Lets say the table has three columns and two rows where the first row is a header and the second row needs to be repeated for each item in a collection of data. Also, the table may be repeated for each item in a collection of data.

I load the document into a Novacode.DocX object then process each paragraph in the Paragraph collection, appending the paragraphs to a new DocX object based on certain instructions. The instructions may indicate that the paragraphs are conditional or repeating.

This works fine until I encounter a table. Each cell in the table is represented as a paragraph (or paragraphs) in the collection of Paragraphs. The only distinguishing property is the paragraph's ParentContainer. When I encounter a paragraph contained in a table, I attempt to append a table to the new document but this never ends up in the right place. There doesn't appear to be any way to determine where in the document the table is to be positioned. I have tried to find a connection between the items in the Tables collection and the items in the Paragraphs collection but there doesn't appear to be anything. Also the Tables collection doesn't appear to have any properties relating to its location in the document.

I am certain it can't be this hard. What am I missing?

1 Answers1

0

I've had similar problems in sorting out what sometimes seems an ambiguous insertion/appending of images w/ Novacode and started putting images in tables to gain better control of placement and alignment in the document.

Significant improvement was found using the InsertTable() command immediately after constructing each table, followed by InsertParagraph([string]).

Not all of the document I'm building is contained in tables. So the in linear sequence

//After building each table.
Novacode.DocX.InsertTable([nameoftable])

// For text content outside of tables 
Novacode.DocX.InsertParagraph([string])

Use of the above in my case enables a completely linear sequence.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135