How do I get the Index of a known cell?

Hi

I need to get the index of a cell so that I can fill a range with a sequential series of values.

If the cell is “G5”, how do I get the Index of that cell?

– the cell definitely has an index because it has a value already - I need to replace the cell value.

You can direclty use the cell name to access it.

For example,

excel.Worksheets[0].Cells[“G5”].PutValue(“Hello World”);

Please check

for reference.

I know that, but I need the cell index.

What I want to do is add an incremental value (1 to 52) starting from cell G5.
So here is the series…

G5 - 1
G6 - 2
G7 - 3
etc.

I thought the easiest way of doing this is a loop using the cell’s index.
Is there an easier way?

Now you can try the following approach:

int startIndex = -1;
for(int i = 0; i < cells.Count; i ++)
{
Cell cell = cellsIdea;
if(cell.Name = “G5”)
{
startIndex = i;
break;
}
}

if(startIndex != -1)
{
for(int i = startIndex; i < startIndex + 52; i ++)
{
Cell cell = cellsIdea;
//do something here

}
}


In future verion, I can add a new GetIndex method, then you can simplify your code to:

Cell cell = cells[“G5”];
int startIndex = cells.GetIndex(cell);
for(int i = startIndex; i < startIndex + 52; i ++)
{
Cell cell = cellsIdea;
//do something here

}

Thanks for that, although I figured out an alternative method.

A GetIndex method would be very useful in future! Cool

@mecED,
Aspose.Excel is discontinued and no more available. It is replaced by Aspose.Cells that is much advanced and supports the latest features available in different versions of MS Excel. You can use CellsHelper.CellNameToIndex() that returns row and column indices using the cell name. Here is an example that demonstrates this feature:

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
string name = "C4";
int row;
int column;
Aspose.Cells.CellsHelper.CellNameToIndex(name, out row, out column);
Console.WriteLine("Row: {0}, Column: {1}", row, column);

For more information on working with Names and Indices, refer to the following article:
Names and Indices

Here is the link to the free trial version of this new product:
Aspose.Cells for .NET(Latest version)

You can download a ready-to-run solution here that can be used to test different features of this product without any coding.