nathanpz
asked on
Opening an Excel File in VB.NET WinForms App
I have a file that I would like to open in excel if the user clicks on the button of a windows form.
What is the simplest VB.NET code for this task?
Will there be any version issues depending on what Excel version the client computer has?
Does a reference have to be made to an Excel OLB in the .NET solution?
Thanks.
What is the simplest VB.NET code for this task?
Will there be any version issues depending on what Excel version the client computer has?
Does a reference have to be made to an Excel OLB in the .NET solution?
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
U can convert the file from .csv to .xls this way.
Public Function ConvertCSVToXLS(ByVal strCSVFile As String, ByVal strXLSFile As String)
Dim oExcel As Excel.Application
Set oExcel = New Excel.Application
Dim oBook As Workbook
Set oBook = oExcel.Workbooks.Open(strC SVFile)
oBook.SaveAs strXLSFile, xlExcel9795
Set oBook = Nothing
oExcel.Quit
Set oExcel = Nothing
End Function
Public Function ConvertCSVToXLS(ByVal strCSVFile As String, ByVal strXLSFile As String)
Dim oExcel As Excel.Application
Set oExcel = New Excel.Application
Dim oBook As Workbook
Set oBook = oExcel.Workbooks.Open(strC
oBook.SaveAs strXLSFile, xlExcel9795
Set oBook = Nothing
oExcel.Quit
Set oExcel = Nothing
End Function
You can open CSV file by this method as well
https://www.experts-exchange.com/questions/20936016/Read-CSV-file-to-array.html
https://www.experts-exchange.com/questions/20936016/Read-CSV-file-to-array.html
ASKER
Thanks 123....
ASKER
Here is the code I have used:
''''''''''''''''''''''''''
Dim ExcelObj As Excel.Application
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
''''''''''''''''''''''''''
''open excel
''''''''''''''''''''''''''
ExcelObj = New Excel.Application()
Dim theWorkbook As Excel.Workbook
theWorkbook = ExcelObj.Workbooks.Open(_p
ExcelObj.Visible = True
End Sub
''''''''''''''''''''''''''
Any ideas?