Show Information in a label

mattcya

Member
Joined
Jun 18, 2004
Messages
16
Programming Experience
Beginner
Hi Guys,

Just want to know how to display a spreadsheet column from excel into a label field.

Here is my code i am new to vb.net so be nice ;)

'Displays Spreadsheet information in label fields

Dim Xl = CreateObject("Excel.Application")

Dim XLB As Object

Dim XlS As Excel.Worksheet

XLB = Xl.Workbooks.Open("c:\Temp\candidate.csv")
XlS = CType(XLB.Worksheets("candidate"), Excel.Worksheet)



Label1.Text = XlS.Columns.Show(1)


Cheers!

Mattcya
 

TPM

Well-known member
Joined
Dec 7, 2004
Messages
623
Location
CA
Programming Experience
3-5
It would probably be easyer to use an ODBC connection.

TPM
 

mattcya

Member
Joined
Jun 18, 2004
Messages
16
Programming Experience
Beginner
So i add a refernce to excel and then connect using a odbc. soryy but would you be able to give me an example

Much appreciated :)
 

Paszt

Staff member
Joined
Jun 3, 2004
Messages
1,500
Location
Raleigh, NC - USA
Programming Experience
Beginner
Remeber this post?: reading from excel sheet

Once you have the data in a dataset (or just a dataTable), you can either add dataBindings or set the value explicitly to a row/Column in the dataset Table.

To add dataBindings, either use the properties pane or use code like this:
Label1.DataBindings.Add("Text",dataSource,dataMember)
Explicitly:
Label1.Text = dataSet.dataTable(index).Rows(index).Item("ColumnName").ToString
 
Top Bottom