I need to open and read a binary Excel file with the .xlsb format just to read a few cells from 3 different sheets. I tried this way that I usually use for .xlsx but it is not working on Using workBook As New XLWorkbook(filePath). What is the best way to do this? Preferably without resorting to paid libraries ... Thank you.
Using openFileDialog1 As OpenFileDialog = New OpenFileDialog()
If openFileDialog1.ShowDialog() = DialogResult.OK Then
txtFicheiro.Text = Path.GetFullPath(openFileDialog1.FileName)
Dim filePath As String = openFileDialog1.FileName
Using workBook As New XLWorkbook(filePath)
Dim workSheet As IXLWorksheet
workSheet = workBook.Worksheet(0)
Dim dt As New DataTable()
Dim firstRow As Boolean = True
For Each row As IXLRow In workSheet.Rows()
If firstRow Then
For Each cell As IXLCell In row.Cells()
dt.Columns.Add(cell.Value.ToString())
Next
firstRow = False
Else
dt.Rows.Add()
Dim i As Integer = 0
For Each cell As IXLCell In row.Cells()
dt.Rows(dt.Rows.Count - 1)(i) = cell.Value.ToString()
i += 1
Next
End If
dataGridView1.DataSource = dt
Next
End Using
End If
End Using