How to make it change excel cell font color as black in template using c#

Gani_tpt 1,221 Reputation points
2021-03-26T05:57:11.9+00:00

I am using below source code to highlight the font color as red if any difference in the value.

Now, before highlighting the color, i just want to set font color in the text as "black" in the defined range template.

How to do this..?

other reference post : how-do-we-highlight-the-cells-in-same-excel-templa.html

public static void WriteToFile(object[,] data, List<Tuple<int, int>> cellsToChangeColor,string rangeStart,string rangeEnd)   
         {  
             Range range = xlWorksheet.get_Range(rangeStart, rangeEnd);  
      //set text font color as "black" in entire range template, before highlighting the different color  
  
             range.set_Value(XlRangeValueDataType.xlRangeValueDefault, data);  
             xlWorksheet.ListObjects.Add(XlListObjectSourceType.xlSrcRange, range,  
            Type.Missing, XlYesNoGuess.xlYes, Type.Missing).Name = "TestTable";  
             xlWorksheet.ListObjects["TestTable"].TableStyle = "TableStyleMedium2";  
      
             List<char> columnToExclude = new List<char>() { 'D', 'H', 'I' };  
             foreach (var item in cellsToChangeColor)  
             {  
                 char column = (char)(item.Item2 + 64);  
                 if (columnToExclude.Contains(column)) continue;  
                 string cell = (char)(item.Item2 + 64) + item.Item1.ToString();  
                 range.Range[cell].Font.Color = ColorTranslator.ToOle(Color.Red);  
             }  
         }  
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
6,972 questions
{count} votes

Accepted answer
  1. Viorel 82,741 Reputation points
    2021-03-26T06:56:38.26+00:00

    Did you try 'range.Font.Color = ColorTranslator.ToOle(Color.Black)'?


0 additional answers

Sort by: Most helpful