Free Support Forum - aspose.com

How to change font color in a given table cell

I can easily change the background color of a given table cell but I can't change the color of the font in the given cell. The text in the table cell is already populated through word templates. I am just looking to change the font color of one of the table cell. Help.

Dim tTable As Aspose.Words.Tables.Table = Nothing
Dim cCell As Aspose.Words.Tables.Cell
Dim intTMProfileTable As Integer = 5
Dim row As Integer = 2
Dim cell As Integer = 3
tTable = CType(dMainDoc.GetChild(NodeType.Table, intTMProfileTable, True), Aspose.Words.Tables.Table)
cCell = tTable.Rows(row).Cells(cell)
cCell.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(91, 39, 122)
'I can do this but I want to change the color of the font that is in the cell

Hi,


Thanks for your inquiry. I believe, you can change the text formatting (color, font size etc) by using the following code snippet:

Document doc = new
Document(@“C:\Temp\in.docx”);

NodeCollection tables = doc.GetChildNodes(NodeType.Table, true);

Table table = (Table)tables[0];

foreach (Cell c in table.GetChildNodes(NodeType.Cell, true))

{

foreach (Run run in c.GetChildNodes(NodeType.Run, true))

{

// Set some font formatting properties

Aspose.Words.Font font = run.Font;

font.Size = 20;

font.Bold = true;

font.Color = System.Drawing.Color.Green;

font.Name = "Verdana";

}

}

doc.Save(@"C:\Temp\out.docx");


You may also want to take a look at the following article on specifying formatting:
http://www.aspose.com/docs/display/wordsnet/Specifying+Formatting

Best Regards,