I am new here to this forum but I was directed here by the Microsoft Forums for this question that I have. So here it goes:
I am currently working on a program through Visual Studio 2013 Express. This program, as it stands, is a display board that I will use in my workplace. For ease of access I created a way to load a Microsoft Excel document to a datagridview. When a button is clicked this operation loads the designated spreadsheet from the C drive of the subject computer and displays it in a similar fashion. The way it currently works is fine...BUT I want to be able to enable the user to load that file whether it is in the format for Microsoft excel or Apache OpenOffice. I have the code setup to where it will "Try" the operation. I want to see if I can get the "If...Then" Operation to execute whichever format that it has to use. Here is the code so far:
Code: Select all
Private Sub LoadXMLButton2_Click(sender As Object, e As EventArgs) Handles LoadXMLButton2.Click
Try
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim dataset As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim path As String = "C:\Numbers.xlsx"
MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" _
+ path + ";Extended Properties=""Excel 12.0"";")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
dataset = New System.Data.DataSet
MyCommand.Fill(dataset)
NumBox1.DataSource = dataset.Tables(0)
MyConnection.Close()
Catch ex As Exception
MsgBox(ex.Message.ToString)
End Try
End Sub
Try to open when button is clicked,
If the document is in microsoft.office.excel... format Then open in the corresponding format.
ElseIf the document is in OpenOffice format Then open the document in that corresponding format.
I don't know if this is too much to be done but if anyone has any suggestions or examples then please let me know! All input is appreciated!
Thank you!