How can i get the Cell address from excel given a row and column number for example
row 2 and col 3 should return C2... Please help
How can i get the Cell address from excel given a row and column number for example
row 2 and col 3 should return C2... Please help
I'm not a big user of VSTO C# - I usually opt for VBA. However, the following pair of functions might be useful for you. Unsure if they can be streamlined some more:
The
RangeAddress
will take any Excel range and throw you back the address. If you want the absolute style (with dollar signs, e.g. $C$3) then you have to change the first two parameters of the get_AddressLocal call to true, true.To get the cell address from a row/col pair, you can use
CellAddress
. It does need a sheet to get the address. However, you could swap in(Excel.Worksheet)ActiveSheet
if you don't want to provide a sheet (this may or may not work, depending on what you have open in your VSTO session).This one (untested) should also work with column addresses over that are over 26:
Corrected: the column address was backwards
I'm using zero-based row and column index. So I had to adapt the code of prior answers to the following. It took some trial and error to get this right for all possible addresses i.E. A1, Z2, AA2, ZZ10, ...
Cells(2, 3).Address
Just an improvement, the col-- was in the wrong place