Excel named column with VB.net

G

Guest

Is it possible to access a named column in an Excel worksheet template through VB.net? I have found how to set individual cell values in the file, but am unable to reference the column by name

I am currently having to do the following
Worksheet.Cells(RowCounter, 1) = dr("Name").ToString(
where RowCounter starts at the row index I want to start at and increments while going through the datarows in a datatable. This way requires me to specify in the VB code which columns (by index) the values should go into. I would like to be able to use the named column from the Excel template to specify the column. This way, the users could add columns to the template, and the data would still appear in the correct columns

Any ideas?
 
P

Paul Clement

¤ Is it possible to access a named column in an Excel worksheet template through VB.net? I have found how to set individual cell values in the file, but am unable to reference the column by name.
¤
¤ I am currently having to do the following:
¤ Worksheet.Cells(RowCounter, 1) = dr("Name").ToString()
¤ where RowCounter starts at the row index I want to start at and increments while going through the datarows in a datatable. This way requires me to specify in the VB code which columns (by index) the values should go into. I would like to be able to use the named column from the Excel template to specify the column. This way, the users could add columns to the template, and the data would still appear in the correct columns.
¤

Actually if the user adds or removes columns the data will appear in a different column. But if you
want to refer to rows and columns independent of their physical location you could assign a named
Range to each column.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
O

onedaywhen

You can use OLEDB and ADO to query Excel data. Reference the column
header e.g. in a SQL SELECT clause could be what you mean by
'reference the column by name' because the column is not referenced by
position at all.

--

Paul Clement said:
¤ Is it possible to access a named column in an Excel worksheet template through VB.net? I have found how to set individual cell values in the file, but am unable to reference the column by name.
¤
¤ I am currently having to do the following:
¤ Worksheet.Cells(RowCounter, 1) = dr("Name").ToString()
¤ where RowCounter starts at the row index I want to start at and
increments while going through the datarows in a datatable. This way
requires me to specify in the VB code which columns (by index) the
values should go into. I would like to be able to use the named
column from the Excel template to specify the column. This way, the
users could add columns to the template, and the data would still
appear in the correct columns.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top