Home All Groups Group Topic Archive Search About

Export array from vb.net to excel

Author
28 Sep 2006 3:59 AM
michealmess
Can anyone help me. I wish to export an array from vb.net to excel
ranges. This will happen for multiple files. The ranges names will not
be start and end in the same cells on all files. How do i do this?

Author
28 Sep 2006 5:41 PM
Steve Long
One way to do this is to write a subroutine in your Excel spreadsheet that
takes either an object or variant as a parameter, convert the object to a
string array and input your values from the array into the range that you
wish. I've done this in VB6 but not .NET. It looks like it should work in
..Net as well. Just include a reference to the Microsoft Excel Object library
(whatever version that's on your machine and the target machines). Then do
something like this:

    Dim o As Excel.Application
    Dim xsheet As Workbook
    Dim myArray(5) As String

    ' is Excel already open?
    o = GetObject(, "Excel.Application")

    ' if not, open it
    If o Is Nothing Then
        o = CreateObject("Excel.Application")
    End If

    For i As Integer = 0 To myArray.GetUpperBound(0)
        myArray(i) = i.ToString()
    Next

    xsheet = o.Workbooks.Open(FileName:="somefilenameandpath")
    xsheet.Application.Visible = True
    ' run the subroutine you want
    xsheet.Application.Run("RoutineName_FileRange", myArray)

HTH
Steve


<michealm***@bigpond.com> wrote in message
Show quoteHide quote
news:1159415945.889864.269810@h48g2000cwc.googlegroups.com...
> Can anyone help me. I wish to export an array from vb.net to excel
> ranges. This will happen for multiple files. The ranges names will not
> be start and end in the same cells on all files. How do i do this?
>
Author
28 Sep 2006 6:36 PM
scorpion53061
http://www.kjmsolutions.com/datasetarray.htm


michealm***@bigpond.com wrote:
Show quoteHide quote
> Can anyone help me. I wish to export an array from vb.net to excel
> ranges. This will happen for multiple files. The ranges names will not
> be start and end in the same cells on all files. How do i do this?
Author
29 Sep 2006 12:12 AM
michealmess
Thanks for the replies but I will not be haing a reference to Excel at
all.
Author
29 Sep 2006 10:41 AM
Pritcham
Hi Micheal

If you're not having any references to Excel then I don't imagine
you're going to be able to do this as ranges and names are Excel
specific so unless you are familiar with the Excel file format and are
comfortable creating files in this format (or you're using a version of
Excel that uses an XML file format) then you're left with the choice of
buying/using an Excel component (Aspose for example) or referencing
Excel.

HTH
Martin

michealm***@bigpond.com wrote:
Show quoteHide quote
> Thanks for the replies but I will not be haing a reference to Excel at
> all.
Author
28 Sep 2006 8:26 PM
scorpion53061
http://www.kjmsolutions.com/datasetarray.htm


michealm***@bigpond.com wrote:
Show quoteHide quote
> Can anyone help me. I wish to export an array from vb.net to excel
> ranges. This will happen for multiple files. The ranges names will not
> be start and end in the same cells on all files. How do i do this?