This project has moved. For the latest updates, please go here.

Table Cell Paragraphs

Jun 14, 2016 at 1:19 PM
Forgive me if I'm missing something but I would like my table cells to not contain a paragraph.

The tables look ok but have the text in the cells has a 10pt spacing after and I'm assuming this is because there is a paragraph in there.

Is there a way to prevent the cell contents rendering inside a paragraph?

Jun 15, 2016 at 6:32 AM
Alternatively, is there a way for me to add a style to only those paragraphs inside the table cell without changing the HtmlToOpenXml code?
Jun 15, 2016 at 7:52 AM

You should have a paragraph inside the table cells.
Instead, I suggest you to modify the cellspacing attribute of the table to decrease. You can also work on Table style.
There is a way to target only the paragraphs inside the table by defining a Paragraph Style and then referencing it as a class name (see documentation > Style).
Jun 16, 2016 at 11:58 PM
Edited Jun 17, 2016 at 12:03 AM
I can add a class name (nospacing) to a table tag but not sure how this would automatically apply a paragraph style to paragraphs within the table since the paragraphs are automatically added by the HtmlToOpenXml library?
<table class="nospacing"> <tr> <td> <p class="?????"></p> </td> </tr> </table> I know how to add a paragraph style to the document and I can understand finding all paragraphs within a table using something like this ...

foreach (var table in mainPart.RootElement.Descendants<Table>())
foreach (var para in table.Descendants<Paragraph>())
// apply paragraph style  ....

and then manually applying the style to each paragraph.

But imagine there is a much nicer way to do it.
Jun 17, 2016 at 5:54 AM
If you define the class on the table, so you should have a Table style. I were talking about class on the paragraphs inside your table.
There is 3 kind of styles: Table, Paragraph and Run. The latter applied to <span>, <i> and so on...

But this doesn't help you?
<table cellspacing="0" cellpadding="0">