Reputation: 543
I'm working on a dll for Excel file. In the dll I want to do a method in which the client will enter the row to get the list from, and then enter the column from and to get list. something like: public List GetValueList(int inRow, string fromColumn, string toColumn)
The problem is- how can I get do it? in Excel there are columns like "AZX", "AA" and so on... I can't just do "fromColumn++".
Any ideas? I hope I explained myself.
Upvotes: 1
Views: 2142
Reputation: 35430
The Cells
member of the Worksheet
object takes both row and column numbers as integers. So you can do something like this:
List<object> GetValueList(Worksheet WS, int inRow, int fromColumn, int toColumn)
{
List<object> MyList = new List<object>(toColumn - fromColumn + 1);
for(int i=fromColumn; i<=toColumn; i++)
MyList.Add(WS.Cells[inRow, i].Value);
return MyList;
}
Note that both fromColumn and toColumn are integers. If you need to convert from an alphabetic column number (like BD or AFH), simply use WS.Range("BD" + "1").Column
, replacing "BD" with the actual column number you have.
Upvotes: 3