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

Table Cell Paragraphs

Jun 14, 2016 at 2: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?

Thanks
Jun 15, 2016 at 7: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?
Coordinator
Jun 15, 2016 at 8:52 AM
Hi,


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 17, 2016 at 12:58 AM
Edited Jun 17, 2016 at 1: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.
Coordinator
Jun 17, 2016 at 6: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">