Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# Excel NotAQuestion
int rows = darray.GetUpperBound(0);
int cols = darray.GetUpperBound(1);
for (int i = 1; i <= rows; i++)
{
    for (int j = 1; j <= cols; j++)
    {
        workSheet_range = mySheet.get_Range(i, j);
        if (workSheet_range.Interior.Color == System.Drawing.Color.Red)
        {
             kauntalda++;
        }
    }
}
Not working!
Posted 18-Sep-12 3:47am
Edited 18-Sep-12 4:17am
v4
Comments
Andrei Straut at 18-Sep-12 8:52am
   
Not here for long
Radzhab at 18-Sep-12 9:22am
   
???
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

//....
workSheet_range = mySheet.get_Range(i, j); 
if(workSheet_range.Interior.Color == System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red)
{
// your stuff goes here
}
/....
  Permalink  
Comments
Radzhab at 19-Sep-12 1:34am
   
workSheet_range = mySheet.get_Range(i, j); this code returns null
 

 
var usedRange = mySheet.UsedRange;
object[,] darray = null;
darray = (object[,]) usedRange.Value;
 
int rows = darray.GetUpperBound(0);
int cols = darray.GetUpperBound(1);
for (int i = 1; i <= rows; i++)
{
for (int j = 1; j <= cols; j++)
{
workSheet_range = mySheet.get_Range(i, j); // return null
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

To get or set a color for cell background, you can use ColorIndex[^] property too.
//chack for white
if(workSheet_range.Interior.ColorIndex == 2)
{
// ... ;)
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 375
1 Sergey Alexandrovich Kryukov 329
2 CPallini 260
3 DamithSL 214
4 Maciej Los 197
0 OriginalGriff 5,455
1 DamithSL 4,457
2 Maciej Los 3,885
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,115


Advertise | Privacy | Mobile
Web03 | 2.8.141216.1 | Last Updated 18 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100