Hello,
I am building a windows form application using visual basic (visual studio 2008).
The idea is to query a MySQL DB and export the results to an excel document.
I managed to do this using this code (I will just show the export to excel part):
Imports Excel = Microsoft.Office.Interop.Excel
Imports System.IO
Imports System.Data
Imports MySql.Data.MySqlClient
Imports System.Configuration
Imports System.Runtime.InteropServices
Private Sub btn_getReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_getReport.Click
Dim wb As Excel.Workbook
Dim ex As New Excel.Application
wb = ex.Workbooks.Add(System.Reflection.Missing.Value)
Dim sheet As Excel.Worksheet = CType(wb.Worksheets.Add, Excel.Worksheet)
sheet.Name = "algo"
Dim i As Integer = 1
Try
While reader.Read
sheet.Cells(i, 1) = CStr(reader.Item(0))
sheet.Cells(i, 2) = CStr(reader.Item(1))
sheet.Cells(i, 3) = CStr(reader.Item(2))
i += 1
End While
Catch MyEx As MySqlException
RaiseEvent MySqlError(Err, MyEx, "read")
Catch exc As Exception
RaiseEvent MySqlError(Err, exc, "read")
End Try
Dim dialog As New SaveFileDialog
Dim result As DialogResult = dialog.ShowDialog
Try
wb.SaveAs(dialog.FileName)
Catch exerr As Exception
End Try
'Show the spreadsheet.
'ex.Visible = True
'wb.Activate()
End Sub
And it works fine on my laptop (which has office 2003 installed), but when I create the setup package and install it on the server where I am going to use it (which does not have office installed), I get this error:
"Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154."
For what I have read, this is a problem while trying to use excel when its not present on the computer, I can understand that, what really confuses me is that I have used apps that export information to excel even running on computers without having office installed on them, how can they do that?
And for the record, I need the excel file, not a CSV.
Thanks a lot.