Revit API - Change Text color in excel

Revit API - Change Text color in excel

Hisham_Odish
Contributor Contributor
810 Views
3 Replies
Message 1 of 4

Revit API - Change Text color in excel

Hisham_Odish
Contributor
Contributor

Hi All, 

I’m exporting schedules to excel and then I want to compare the value of 2 cells. If they are not equal then change the font to red. I’m able to format the font to bold, but don’t know how to change the color.

thanks for any help.

 

 

 

            xlRange = xlWorkSheet.get_Range("B4");
              xlRange2 = xlWorkSheet.get_Range("J4");
            if (xlRange.Value.ToString() != xlRange2.Value.ToString())
            {
                xlRange = xlWorkSheet.get_Range("J4");
                xlRange.Font.Bold = true;
                xlRange.Font.Color = "Red";
            }

0 Likes
811 Views
3 Replies
Replies (3)
Message 2 of 4

josh.roth.MEI
Enthusiast
Enthusiast

Hi @Hisham_Odish ,

 

I think the problem lies with the value you are trying to assign to the font color. For your last line, try this instead:

 

xlRange.Font.ColorIndex = 3;

 

0 Likes
Message 3 of 4

Sean_Page
Collaborator
Collaborator

Excel.Range rng2 = this.Application.get_Range("A1");
rng2.Font.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red);

Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect
0 Likes
Message 4 of 4

Hisham_Odish
Contributor
Contributor

hi @ jrothMEI, @ spage

thanks for your responses.

i tried your solution but didn't work. however when plugged in this value and it worked "0,0,255". also noticed the numbers should be right to left rather left to right. when using other coding, i usually type "255,0,0" for red color. but in this case i had to reverse the order of number to "0,0,255" to get color red.

thanks 🙂