Accessing information of TableStyles

Hi,

In Word you can specify different fonts used for everything configurable via TableStyleOptions such as first row, last row, first column…

When overwriting the default paragraph formatting (NORMAL constant) in the Word template, it looks like this information is not applied when applying a table style.

Thus I want to know how to access the used font name to set it manually in any paragraph which is rendered inside a cell. I know that I can access a font using tableStyle.getFont() but this is only the general one and I don’t know how to get access the one for e.g. last row.

Best,
Tobias

Hi Tobias,

Thanks for your inquiry. Please use the following code snippet to be able to access/set table cell paragraph formatting and font styles:

NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);
Table table = (Table) tables[0];
Cell cell = table.Rows[1].Cells[1];
Paragraph paragraph = cell.Paragraphs[0];
Run run = paragraph.Runs[0];
// Set font formatting properties
Aspose.Words.Font font = run.Font;
font.Size = 20;
font.Bold = false;
font.Color = System.Drawing.Color.Green;
font.Name = "Verdana";
// Set paragraph formatting
ParagraphFormat paragraphFormat = paragraph.ParagraphFormat;
paragraphFormat.FirstLineIndent = 8;
paragraphFormat.Alignment = ParagraphAlignment.Justify;
paragraphFormat.KeepTogether = true;

Moreover, for specifying formatting, I would suggest you to please visit the following links:
https://docs.aspose.com/words/net/applying-formatting/

I hope, this will help.

Best Regards,

Hi Awais,

Thank you for the fast reply.

My problem is not related to set a font for a paragraph or run. My problem is to find out which font I should use according to a table style definition.

TableStyle tableStyle = (TableStyle) builder.getDocument().getStyles().get("My Table Style Name");

E.g.which font name / size do I need to use in the first row according to the table style font configuration of my table. I haven’t found a way to access it.

tableStyle.getFont() would just return me the general font configured but not the one explicitly overwritten for the first row (you can configure this in Word).

Cheers,
Tobias

Hi,

Thanks for your inquiry. Unfortunately, at the moment this feature is not supported. I have linked your request to the appropriate new feature. You will be notified as soon as it is added.

Please let us know if you need more information, We are always glad to help you.

Best Regards,

Hi Tobias,

Thanks for your inquiry.

In addition, you may want to use the work around like below in the mean time to find the table style formatting of a certain table style.

// Create a new table.
Table table = new Table(doc);
table.EnsureMinimum();
doc.FirstSection.Body.AppendChild(table);
// Apply the desired style.
table.StyleIdentifier = StyleIdentifier.LightShadingAccent2;
table.StyleOptions = TableStyleOptions.FirstRow;
// Call this method to expand formatting from table styles onto runs and paragraphs.
doc.ExpandTableStylesToDirectFormatting();
// This is the font used in the first row of the table style.
Aspose.Words.Font firstRowFont = table.FirstRow.FirstCell.FirstParagraph.ParagraphBreakFont;
Color color = firstRowFont.Color;

If we can help you with anything else, please feel free to ask.

Thanks,

The issues you have found earlier (filed as WORDSNET-5312) have been fixed in this Aspose.Words for .NET 19.6 update and this Aspose.Words for Java 19.6 update.