开发者

C# Loop round a Range.Value which has 2 objects [0,0] to find if string = variable

开发者 https://www.devze.com 2023-03-01 21:00 出处:网络
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

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;
        }
    }
0

精彩评论

暂无评论...
验证码 换一张
取 消