Hi guys,
First of all, thank you for this wonderful library! It has helped me immensely.
I faced this exact issue and I was able to resolve it by adding styles to each <p> tag within each <td> tag. I'm using the html agility pack to do some pre-processing before parsing my html to Open XML.
First of all, thank you for this wonderful library! It has helped me immensely.
I faced this exact issue and I was able to resolve it by adding styles to each <p> tag within each <td> tag. I'm using the html agility pack to do some pre-processing before parsing my html to Open XML.
var htmlDoc = new HtmlDocument();
htmlDoc.LoadHtml(html);
// process tables
HtmlNodeCollection tableNodeCollection = htmlDoc.DocumentNode.SelectNodes("//table");
if (tableNodeCollection != null)
{
foreach (HtmlNode tableNode in tableNodeCollection)
{
// apply styles to table
tableNode.Attributes.Add("style", "font: 10pt Calibri; width: auto;");
// apply styles to paragraphs inside table
HtmlNodeCollection pNodeCollection = tableNode.SelectNodes("//p");
foreach (HtmlNode p in pNodeCollection)
{
p.Attributes.Add("style", "margin: 0; padding: 0;");
}
}
}
// send processed html back to string
html = htmlDoc.DocumentNode.WriteTo();
I hope this helps. The problem that I am having now is getting the table width to auto-size according to the contents. width: auto does not seem to work as the table always fills the entire document space between the margins. Any ideas on that one?