0

I have exported an excel document. In that, I have to apply the background color of the entire row based on some conditions. For example, If I have 1000 lines in the excel, I want to apply the background in 100 rows only.

I tried to set the color with range values. I am able to apply a color based on that. But I couldn't apply particular rows alone.

objSHT.Range["A1: A11"].Interior.Color = ColorTranslator.ToOle((System.Drawing.Color)colorConverter.ConvertFromString("#97C2EC"));

Could you please provide me the solution to apply the color in an entire row (particular row - based on column value condition)?

Dennis VW
  • 2,977
  • 1
  • 15
  • 36

1 Answers1

0

Works perfectly :)

 for (int z=1;z<30;z++)
        {
            Microsoft.Office.Interop.Excel.Range row = xlWorkSheet.Rows[z];
            row.EntireRow.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Azure); ;
        }

I was looking for that some time ago, now i figured out how to do it :D

var col2 = xlWorkSheet.UsedRange.Columns["I:I", Type.Missing];

            foreach (Microsoft.Office.Interop.Excel.Range item in col2.Cells)
            {
                if (Convert.ToString(item.Value) == null)
                {
                    //item.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Cyan);
                    item.EntireRow.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Cyan);

                }

                if (Convert.ToString(item.Value) != null)
                {
                    if (Convert.ToString(item.Value) == "Afterbuild")
                    {
                        item.Value = "Afterbuild";

                    }
                    else
                    {
                        if (Convert.ToInt32(item.Value) < 0)
                        {
                           //item.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
                            item.EntireRow.Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Yellow);
                        }
                    }
                }
            }

So, based on conditions (values) in column "I" i do change color

Kuba Do
  • 155
  • 9