Hi,
I am trying to change the text colour in an existing document with the following code:
cell.FirstParagraph.Runs[0].Font.Color = Color.Pink;
cell.FirstParagraph.Runs[0].Text = string.IsNullOrEmpty(textToAdd) ? string.Empty : textToAdd;
The text is still black after this code has run.
How can I change the text colour?
Cheers
Paul
Hi,
I am trying to change the text colour in an existing document with the following code:
cell.FirstParagraph.Runs[0].Font.Color = Color.Pink;
cell.FirstParagraph.Runs[0].Text = "Some text I would like to change the colour of";
The text is still black after this code has run.
How can I change the text colour?
Cheers
Paul
Hi
Thanks for your request. Paragraph can contain any number of run nodes. To change color of a paragraph you should change color of each run. Please try using the following code to achieve what you need:
// Open document.
Document doc = new Document("in.doc");
Table tabl = (Table) doc.GetChild(NodeType.Table, 0, true);
// Get all Run nodes.
NodeCollection runs = tabl.FirstRow.FirstCell.GetChildNodes(NodeType.Run, true);
// Set color of text in each run.
foreach(Run run in runs)
run.Font.Color = Color.Pink;
doc.Save("out.doc");
Best regards,