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 7,903
1 Sergey Alexandrovich Kryukov 7,142
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,820


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.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