Really hope someone can help out.
Dim worksheet As Cells.Worksheet = Nothing
Dim stream As Stream = Nothing
Dim loadOptions As LoadOptions = Nothing
Dim workbook As Workbook = Nothing
Private Sub btnOpenFileDialog_Click(sender As Object, e As EventArgs) Handles btnOpenFileDialog.Click
Dim openFileDialog As New OpenFileDialog
openFileDialog.InitialDirectory = “C:\Users\Roman\Desktop”
openFileDialog.Filter = “xlsx files (.xlsx)|.xlsx”
openFileDialog.FilterIndex = 0
openFileDialog.RestoreDirectory = True
If openFileDialog.ShowDialog() = DialogResult.OK Then
Try
If Path.GetExtension(openFileDialog.FileName) = “.xlsx” Then
stream = New FileStream(openFileDialog.FileName, FileMode.Open)
loadOptions = New LoadOptions(LoadFormat.Xlsx)
ElseIf Path.GetExtension(openFileDialog.FileName) = “.xls” Then
stream = New FileStream(openFileDialog.FileName, FileMode.Open)
loadOptions = New LoadOptions(LoadFormat.Excel97To2003)
End If
If stream IsNot Nothing then
GridDesktop.ImportExcelFile(stream)
workbook = New Workbook(stream, loadOptions)
worksheet = workbook.Worksheets(workbook.Worksheets.ActiveSheetIndex)
End If
Catch Ex As Exception
MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)
Finally
If (stream IsNot Nothing) Then
stream.Close()
End If
End Try
End If
End Sub