Reference Excel Cells by Cell names

3 views
Skip to first unread message

chriscap

unread,
Apr 10, 2008, 8:22:03 PM4/10/08
to CSVChat
Is it possible to get to a cell by the excel cell name like "C3" or
"AA12"? I haven't seen a way thus far.

Is there a way to go directly to a named cell or range? Say I have
data starting at some arbitrary location (say C15). I would rather
have the flexibility to change that location by using a named cell.
Is this possible?

Thanks

shriop

unread,
Apr 10, 2008, 10:55:58 PM4/10/08
to CSVChat
You can get to a cell by index using [x,y], which would just require a
translation of the name to indexes, which I happen to already have
internally and I'm pasting my code below. There's no current way to
access cells based off of a named range. I've pondered it, but there
was actually a lot more to named regions than I had expected, relative
positions vs absolute, etc, and I couldn't decide on how the interface
would work on it.

private static Point CalculatePoint(string cellName)
{
Point cell = new Point();

int colLength = 0;
int colCount = 0;

char currentLetter = cellName[colLength++];
while (currentLetter > '9')
{
colCount = colCount * 26 + (currentLetter - 'A' + 1);
currentLetter = cellName[colLength++];
}

cell.X = colCount - 1;
cell.Y = Int32.Parse(cellName.Substring(colLength - 1)) - 1;

return cell;
}

private class Point
{
public int X;
public int Y;
}

Bruce Dunwiddie

chriscap

unread,
Apr 11, 2008, 11:54:43 AM4/11/08
to CSVChat
Thanks for that. Named ranges would be really useful. I like how
this library can do XLS, CSV, XML, etc... all in one library. I may
be forced to use a different one since I need to parse CSV and excel
files, but I need to use named ranges. I think it would be a very
useful addition if you ever got the chance.
Reply all
Reply to author
Forward
0 new messages