Excel range object into VB.net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Larry Jones

    #1

    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!
  • scorpion53061

    #2
    Re: Excel range object into VB.net

    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" <larryj@frontie rnet.net> wrote in message
    news:larryj@fro ntiernet.net:[color=blue]
    > 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![/color]

    Comment

    • Rob Nicholson

      #3
      Re: Excel range object into VB.net

      > I want to place information from an active Excel spreadsheet to a VB.net[color=blue]
      > 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.[/color]

      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.EventArg s) Handles MyBase.Load
      Dim ExcelApp As New Excel.Applicati on
      Dim Workbook As Excel.Workbook =
      ExcelApp.Workbo oks.Open("c:\sc ratch\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\book 1.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.


      Comment

      Working...