OpenXML nested tables
Asked Answered
P

1

8

I am trying to insert a Table into a TableCell, but when I try to open it in MS Word I get a message like: "a <p> is required before a </tc>".

When I open the file in compatibility mode the table formatting looks perfect but the table lines are missing. Inserting simple text into the cell works fine, the issue only happens when I try to insert a whole table.

Inserting the Table in the document outside the other table also works fine.

Prudy answered 19/12, 2010 at 21:32 Comment(0)
C
16

If you create a nested table structure in Word, and look at the resulting XML, you will see something like:

      <w:tc>
        <w:tcPr>
          <w:tcW w:w="4621" w:type="dxa"/>
        </w:tcPr>
        <w:tbl>..</w:tbl>
        <w:p/>
      </w:tc>

As per the message, looks like you need <w:p/> after your table, and before the closing tc tag.

Cordy answered 19/12, 2010 at 22:41 Comment(2)
I am doing this in code. I created a new Paragraph added it to the TableCell and added the Table to the Paragraph but then I got an unspecified error. Will post some code example tomorrow.Prudy
Don't add the w:tbl to a w:p. Add a w:tbl directly to the w:tc, then add a new w:p to the w:tc.Cordy

© 2022 - 2024 — McMap. All rights reserved.