Hi, Support,
How to format the fontstyle and paragraphstyle for the texts in table cells?
Thanks for you help!
Ducaisoft
Hi, Support,
How to format the fontstyle and paragraphstyle for the texts in table cells?
Thanks for you help!
Ducaisoft
To apply direct Font formatting on all Text (Run) nodes in Table:
Table table_in_docx = doc.FirstSection.Body.Tables[0];
foreach (Run run in table_in_docx.GetChildNodes(NodeType.Run, true))
{
run.Font.Color = Color.Red;
run.Font.Bold = true;
}
To apply direct formatting on all Paragraph nodes in Table
foreach (Paragraph paragraph in table_in_docx.GetChildNodes(NodeType.Paragraph, true))
{
paragraph.ParagraphFormat.Alignment = ParagraphAlignment.Center;
paragraph.ParagraphFormat.SpaceAfter = 0;
}
You can also apply formatting on Run and Paragraph Nodes via Styles. Please check following C# code of Aspose.Words for .NET:
Style fontStyle = doc.Styles.Add(StyleType.Character, "fontstyle");
fontStyle.Font.Color = Color.Green;
fontStyle.Font.Italic = true;
foreach (Run run in table_in_docx.GetChildNodes(NodeType.Run, true))
run.Font.Style = fontStyle;
Style paragraphStyle = doc.Styles.Add(StyleType.Paragraph, "paragraphstyle");
paragraphStyle.ParagraphFormat.Alignment = ParagraphAlignment.Center;
paragraphStyle.ParagraphFormat.SpaceAfter = 0;
foreach (Paragraph paragraph in table_in_docx.GetChildNodes(NodeType.Paragraph, true))
paragraph.ParagraphFormat.Style = paragraphStyle;
Hope, this helps.