Outputting to Excel

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • almurph@altavista.com

    Outputting to Excel

    Hi everyone,


    I'm trying to output some numbers to an Excel file. the first number
    in A1 the second in A2, you know like this:

    1
    2
    3
    4
    etc...

    Anyway, can anyone give me a few pointers as how to do it. I have
    imported the Excell dll and can create an object of it like:

    Dim oExcel As Excel.Applicati on

    but after that I start to get confused. Can you help me please? Any
    suggestions/comment/code-samples would be most appreciated.

    Thank,
    Al.

  • Mythran

    #2
    Re: Outputting to Excel



    <almurph@altavi sta.comwrote in message
    news:7dbfee14-1353-419e-9be8-c2661d8916bf@t5 5g2000hsa.googl egroups.com...
    Hi everyone,
    >
    >
    I'm trying to output some numbers to an Excel file. the first number
    in A1 the second in A2, you know like this:
    >
    1
    2
    3
    4
    etc...
    >
    Anyway, can anyone give me a few pointers as how to do it. I have
    imported the Excell dll and can create an object of it like:
    >
    Dim oExcel As Excel.Applicati on
    >
    but after that I start to get confused. Can you help me please? Any
    suggestions/comment/code-samples would be most appreciated.
    >
    Thank,
    Al.
    >
    Here is an example I threw together for ya :)

    Private Sub WriteToNewWorkB ook(ByVal WorkbookPath As String)
    Dim app As Excel.Applicati on = New Excel.Applicati on()

    ' Create a new workbook to write to.
    Dim wb As Excel.Workbook = app.Workbooks.A dd()

    Try

    ' Get a reference to the active worksheet.
    Dim ws As Excel.Worksheet = _
    DirectCast(wb.A ctiveSheet, Excel.Worksheet )

    ' Write the values to the first cell in the first 10 rows.
    For i As Integer = 1 To 10
    ' Get a reference to the first cell in each row.
    Dim cell As Excel.Range = _
    DirectCast(ws.C ells.Item(i, 1), Excel.Range)

    ' Write the value to the cell.
    cell.Value = i
    Next i

    ' Save the workbook file. Make sure the file doesn't exist first!
    If System.IO.File. Exists(Workbook Path)
    Throw New Exception( _
    "The specified workbook path already exists." _
    )
    End If

    wb.SaveAs(Workb ookPath)
    Finally
    ' Close the workbook file.
    wb.Close(False)

    ' Close the Excel application.
    app.Quit()

    WriteLn("HERE")
    End Try
    End Sub

    HTH,
    Mythran


    Comment

    • rowe_newsgroups

      #3
      Re: Outputting to Excel

      On Feb 14, 11:41 am, "almu...@altavi sta.com" <almu...@altavi sta.com>
      wrote:
      Hi everyone,
      >
      I'm trying to output some numbers to an Excel file. the first number
      in A1 the second in A2, you know like this:
      >
      1
      2
      3
      4
      etc...
      >
      Anyway, can anyone give me a few pointers as how to do it. I have
      imported the Excell dll and can create an object of it like:
      >
      Dim oExcel As Excel.Applicati on
      >
      but after that I start to get confused. Can you help me please? Any
      suggestions/comment/code-samples would be most appreciated.
      >
      Thank,
      Al.
      Have you searched in the following two places? There is a lot of
      samples for this type of thing:




      After searching, if you run into a specific problem and you can't find
      an answer for it, post back and I or someone else will take a look and
      try to help you out.

      Thanks,

      Seth Rowe [MVP]

      Comment

      • Walter Mark Worsfold

        #4
        Re: Outputting to Excel

        Alternatively you could use a stream/filewriter, and write those pieces to a
        file, and exactly in the format you want. Or if the data is coming from a
        database, see if the database will export directly to excel like sql server
        does via dts, and so can ms access.

        --
        Regards

        Mark Worsfold MCP


        <almurph@altavi sta.comwrote in message
        news:7dbfee14-1353-419e-9be8-c2661d8916bf@t5 5g2000hsa.googl egroups.com...
        Hi everyone,
        >
        >
        I'm trying to output some numbers to an Excel file. the first number
        in A1 the second in A2, you know like this:
        >
        1
        2
        3
        4
        etc...
        >
        Anyway, can anyone give me a few pointers as how to do it. I have
        imported the Excell dll and can create an object of it like:
        >
        Dim oExcel As Excel.Applicati on
        >
        but after that I start to get confused. Can you help me please? Any
        suggestions/comment/code-samples would be most appreciated.
        >
        Thank,
        Al.
        >

        Comment

        • Bill Voorhees

          #5
          Re: Outputting to Excel

          The most easy way to do that is to create a text file named numbers.csv and
          writeline each number. Excel will read the file.

          <almurph@altavi sta.comwrote in message
          news:7dbfee14-1353-419e-9be8-c2661d8916bf@t5 5g2000hsa.googl egroups.com...
          Hi everyone,
          >
          >
          I'm trying to output some numbers to an Excel file. the first number
          in A1 the second in A2, you know like this:
          >
          1
          2
          3
          4
          etc...
          >
          Anyway, can anyone give me a few pointers as how to do it. I have
          imported the Excell dll and can create an object of it like:
          >
          Dim oExcel As Excel.Applicati on
          >
          but after that I start to get confused. Can you help me please? Any
          suggestions/comment/code-samples would be most appreciated.
          >
          Thank,
          Al.
          >

          Comment

          • rowe_newsgroups

            #6
            Re: Outputting to Excel

            The most easy way to do that is to create a text file named numbers.csv and
            writeline each number. Excel will read the file.
            But you lose the formatting functionality, which though not specified
            in the original post, most likely is a requirement or will soon be
            added as a requirement. I would rather do the Office Interop now and
            save the time during maintenance.

            Thanks,

            Seth Rowe [MVP]

            Comment

            Working...