How to set "foreground" color for a cell in a mailmerge document

We already have code that sets background color using a special merge field handler like this:

DocumentBuilder.MoveToMergeField(mergeFieldName);
Color color = Color.FromName(mergeFieldValue);
if (DocumentBuilder.CurrentParagraph.IsInCell)
    DocumentBuilder.CellFormat.Shading.ForegroundPatternColor = color;
else
    DocumentBuilder.CurrentParagraph.ParagraphFormat.Shading.ForegroundPatternColor = color; // Untested

Notice that the merge field’s value contains the named color (It’s a status: Red, Yellow, Green)
Now I have a request for the same functionality but for font/foreground color.
The content of the table cell is something like this:
<<MergeFieldThatChangesForegroundColor>><<AnotherMergeField>> some text
I would like to alter the color of the entire cell or paragraf to the desired color.
I have tried:

DocumentBuilder.Font.Color = color;

But nothings happens as I don’t have anything to write to the document when I’m in the handler for “MergeFieldThatChangesForegroundColor”.
Suggestions?

Hi

Thanks for your inquiry. I think, you can get paragraph, where merge field is located, get all runs in this paragraph and change font color. For example, see the following code:

// open source document.
Document doc = new Document(@"Test001\in.doc");
DocumentBuilder builder = new DocumentBuilder(doc);
// move to mergefield
builder.MoveToMergeField("test");
// Get current paragraph
Paragraph par = builder.CurrentParagraph;
// Get runs in this paragraph.
NodeCollection runs = par.GetChildNodes(NodeType.Run, true);
// Loop through all runs and change font color
foreach(Run run in runs)
    run.Font.Color = Color.Red;
// Save output document
doc.Save(@"Test001\out.doc");

Hope this helps.
Best regards.

Thanks!

// Loop through all runs in current paragraph and change font color
foreach(Run run in _documentBuilder.CurrentParagraph.GetChildNodes(NodeType.Run, true))
    run.Font.Color = color;

Did the trick.