I am using Aspose.Cells
and I have created a Range of cells. This range prod开发者_开发问答uces a range.Value
which consists of 2 objects [row,column]. I now want to loop round these objects which in my case is 1 row and 33 columns with each column having a string 'day' inserted.
So basically I want to loop round and add an if statement such as
if (range.Value.ToString() == "Sat")
{
range.ApplyStyle(backgroundColour, flg);
}
Do I someway have to loop the 33 objects(columns)?
Each range value expression looks like ((object[,])(range.Value))[0, 0]
whew the value in this case is Fri and then ((object[,])(range.Value))[0, 1]
where the value is Sat and so on.
You can iterate over the whole range like this:
object[,] rng = (object[,])range.Value;
for (int row = rng.GetLowerBound(0); row <= rng.GetUpperBound(0); row++)
{
for (int day = rng.GetLowerBound(1); day <= rng.GetUpperBound(1); day++)
{
string dayName = rng[row,day] as string;
}
}
精彩评论