0

So usually when you write to an excel worksheet it's something like this oSheet.Cells[1, 2] you supply the int row and then supply the column int.

Well I have a config file thats about 70 columns that range from H to CE to DF ect.

How do you write to a column like so? oSheet.Cells[1, AF]?

I hope this makes sense

user2864740
  • 60,010
  • 15
  • 145
  • 220
  • possible duplicate of [What is the algorithm to convert an Excel Column Letter into its Number?](http://stackoverflow.com/questions/667802/what-is-the-algorithm-to-convert-an-excel-column-letter-into-its-number) – CheGueVerra Apr 13 '14 at 22:47

2 Answers2

1

You can reference excel Ranges using A1 notation. Try something like

oSheet.Range("AF1")

Then to do this for different letters, you can concatenate

Col = "A"
oSheet.Range( Col & "1" )

Edit: sorry, realized those should be parens (had square brackets).

duncan
  • 446
  • 3
  • 7
0

Worksheet.Cells returns a Range object.

The Item/indexer of the Range object already accepts Excel-style values for the column index. The difference is merely between using an integer for the column value, or a string for the value.

[Column index is a] number or string that indicates the column number of the cell you want to access, starting with either 1 [integer] or "A" [string] for the first column in the range.

So, oSheet.Cells[1, "AF"] would return the desired result (Range).

user2864740
  • 60,010
  • 15
  • 145
  • 220