471,596 Members | 941 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,596 software developers and data experts.

Excel range object into VB.net


I want to place information from an active Excel spreadsheet to a VB.net
form. I just want to place numbers from an Excel cell in a standard
VB.net text box. Does anyone have sample code to demonstrate this
process? I have tried coding the process myself without success. I have
just purchased a 2003 version of VB.net and I am not sure if it is me or
changes in the program. I would like a working example to check my
setup.

Thanks,

Larry Jones
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
2 2173
Please forgive my inability to decipher your intent but it is not clear
to me what you are trying to do.

You want to put the contents of one cell or an entire worksheet in a
textbox?

"Larry Jones" <la****@frontiernet.net> wrote in message
news:la****@frontiernet.net:
I want to place information from an active Excel spreadsheet to a VB.net
form. I just want to place numbers from an Excel cell in a standard
VB.net text box. Does anyone have sample code to demonstrate this
process? I have tried coding the process myself without success. I have
just purchased a 2003 version of VB.net and I am not sure if it is me or
changes in the program. I would like a working example to check my
setup.

Thanks,

Larry Jones
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 21 '05 #2
> I want to place information from an active Excel spreadsheet to a VB.net
form. I just want to place numbers from an Excel cell in a standard
VB.net text box. Does anyone have sample code to demonstrate this
process? I have tried coding the process myself without success. I have
just purchased a 2003 version of VB.net and I am not sure if it is me or
changes in the program. I would like a working example to check my
setup.


Can we assume that Excel is also installed on the server? If so, then the
way to
approach this is to use the Excel object library to open the Excel file and
parse it. There's a bit of steep learning curve with Excel but I've done a
lot of Excel VBA work so can help out. This page_load event handler does
something like you're after:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim ExcelApp As New Excel.Application
Dim Workbook As Excel.Workbook =
ExcelApp.Workbooks.Open("c:\scratch\book1.xls")
Dim Worksheet As Excel.Worksheet = Workbook.Sheets(1)
TextBox1.Text = Worksheet.Range("A1").Value
Workbook.Close(False)
ExcelApp.Quit()
End Sub

This does the following:

o Creates an Excel application object
o Opens the c:\scratch\book1.xls
o Finds the first sheet
o Copies the value from cell A1 into the textbox

Along the right lines?

Some issues:

o You'll need Excel installed and therefore a license
o You'll get access denied when you try and creat the Excel app unless the
IIS accounts have the correct access
o How you get the book1.xls uploaded to the server I leave as an exercise
for the reader.

Cheers, Rob.
Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Allison Bailey | last post: by
4 posts views Thread by IMS.Rushikesh | last post: by
22 posts views Thread by Howard Kaikow | last post: by
4 posts views Thread by goonsquad | last post: by
7 posts views Thread by Alan Roberts | last post: by
18 posts views Thread by Frank M. Walter | last post: by
reply views Thread by Anwar ali | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.