We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Indexing rule

First of all, thank you for the help regarding the chart color.I would like to find out if there is an indexing method in the range object of Aspose.cell. For example, if I use the Microsoft Interop , the code such as below can be written.
for (int index = 0; index < outputs.Count; index++){
excelRange[index + 1];
where excelRange is a excel range object of Interop. So, for example,if the excelRange refers to the cells “A1:B2”, excelRange[0] refers to cell A1, excelRange[1] refers to A2, excelRange[2] refers to B1 and excelRange[3] refers to B2.
Is there any way that I can switch this code using Aspose.Cell? In other words, is there a good way to index a cell in a range without knowing the exact cell address(sth like A1, A2…etc)?
Thank you.

This Topic is created by Amjad_Sahi using the Email to Topic plugin.


Thanks for your query.

Well, in Aspose.Cells, Range[row,col] refers to the Cell object (based on respective row/column indices), so you may easily loop through the range area and perform your desired task accordingly. See the sample code for your reference:
Sample code:

 //Instantiate a new Workbook.
            Workbook workbook = new Workbook();
            //Get the first worksheet in the workbook.        
            Worksheet worksheet1 = workbook.Worksheets[0];
            //Create a range of cells based on H1:J4.
            Range range = worksheet1.Cells.CreateRange("H1", "J4");
            //Name the range.        
            range.Name = "MyRange";
            //Identify range cells.
            int firstrow = range.FirstRow;
            int firstcol = range.FirstColumn;
            int trows = range.RowCount;
            int tcols = range.ColumnCount;
            //Input some data into cells in the range.        

            for (int i = 0; i < trows; i++)
                for (int j = 0; j < tcols; j++)

                    range[i, j].PutValue(i.ToString() + "," + j.ToString());
                    Console.WriteLine(range[i, j].Name);//print the cell name.   


            //Save the excel file.

Hope, this helps a bit.

Thank you.