Author Topic: vb.net Excel connection fail!!!!  (Read 2707 times)

0 Members and 1 Guest are viewing this topic.

Ricky_76

  • Guest
vb.net Excel connection fail!!!!
« on: June 07, 2007, 11:15:34 AM »
Hi,

I have some problem with my last application.
I work with vb.net 2005 and I have used the PIA to connect my application with excel file.
All the staff works very well, but I need to let it work in a computer with Office 2000 and the PIA works only for Office XP, 2003 or 2007.
I have modified the application using alternative methods:


Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
xlApp = CreateObject("Excel.Application")
...


but during the execution the program stop with the following error:

"Unable to cast COM object of type 'System.__ComObject' to interface type 'Excel.Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Libreria non registrata. (Exception from HRESULT: 0x8002801D (TYPE_E_LIBNOTREGISTERED))."

"Libreria non registrata"
means
"Library not registered"


HOW TO solve the problem??

I have uninstalled office 2003 from my computer, and then I have installed the 2000 version. It works, but in some other computers doesn't.

tnx a lot

/r


ps
I can't install office xp or greater in the computer where the application have to run! :(

Fatty

  • Guest
Re: vb.net Excel connection fail!!!!
« Reply #1 on: June 07, 2007, 02:26:02 PM »
Here is the function from one of my prog's
I think that it may helps

~'J'~

Code: [Select]
    Friend Function ReadExcel(ByVal Path As String) As String(,)

        Dim app As Excel.ApplicationClass = New Excel.ApplicationClass
        Dim workBook As Excel.Workbook = app.Workbooks.Open(Path, 0, True, 5, "", "", True, Excel.XlPlatform.xlWindows, "" & Microsoft.VisualBasic.Chr(9) & "", False, False, 0, True, 1, 0)
        Dim workSheet As Excel.Worksheet = CType(workBook.Worksheets(1), Excel.Worksheet)
        Dim SheetRange As Excel.Range = CType(workSheet.UsedRange, Excel.Range)
        Dim rowIndex As Long = SheetRange.Rows.Count
        Dim colIndex As Long = SheetRange.Columns.Count
        Dim valArray(0 To rowIndex - 1, 0 To colIndex - 1) As String
        Dim itm As String
        Try


            For i As Long = 1 To rowIndex
                For j As Long = 1 To colIndex
                    Dim val As String = CType(SheetRange.Cells(i, j), Excel.Range).Value.ToString
                    If Not val Is Nothing Then
                        itm = val

                    Else

                        itm = "Empty"
                    End If
                    valArray(i - 1, j - 1) = itm
                Next
            Next


        Catch ex As Autodesk.AutoCAD.Runtime.Exception
            app.Quit()
        End Try
        Return valArray
    End Function

Ricky_76

  • Guest
Re: vb.net Excel connection fail!!!!
« Reply #2 on: June 10, 2007, 09:43:36 AM »
Tnx,

I'll try it!

/r