I have a excell file with 10 sheets with headers in row 1.
I’m using this bit of code to get a range of those headers. That part works fine.
string lastColumn = worksheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell).Address[Type.Missing].Substring(1, 1);
Range amountRange = worksheet.Range["A1", string.Format("{0}1", lastColumn)];
The thing is I’ getting a new sheet with the same headers, but I have to add one dinamically. I have to read it from a DB.
So if I change the code to this, I get just the last column. No sweat.
string lastColumn = worksheet.Cells.SpecialCells(XlCellType.xlCellTypeLastCell).Address[Type.Missing].Substring(1, 1);
Range amountRange = worksheet.Range[string.Format("{0}1", lastColumn)];
But what I want is to get the last column plus one and I’m struggling with it.
My first thought was lastColumn + 1, but it does not work.
Any ideas.
Rui Martins?
I solved it myself.
After getting the column name of the last column, I converted it to a number, added 1 and then converted back into a column name.
That easy.