void HighlightCells(ExcelInterop.Range range, Core.Parser parser) { if (range.Cells.Count > 1) { foreach (var cell in range.Cells.Cast<ExcelInterop.Range>()) { HighlightCells(cell, parser); } } else { var text = (string)range.Text; if (string.IsNullOrEmpty(text)) return; // reset text color. range.Font.ColorIndex = ExcelInterop.XlColorIndex.xlColorIndexAutomatic; foreach (var f in parser.Parse(text)) { // NOTE: indices of Characters are 1-based range.get_Characters(f.Start + 1, f.Length).Font.Color = f.ForegroundColor; } } }