0

I'm trying to read the values from an excel file's stream, unfortunately, after installing ExcelDataReader and ExcelDataReader.DataSet from NuGet packages, I can't create the class IExcelDataReader. It doesn't read the Import neither.

Imports System.IO
Imports ExcelDataReader
Public Class ExcelMng
    Public Function Values_GET(stream As Stream)
        Dim reader As IExcelDataReader
    End Function
End Class

Project's Code

Error found:

'IExcelDataReader' it's not defined.

Things I have tried:

  • Uninstall the packages and installing them again.
  • Changing versions of the packages installed (I lower them down to 3.3).
  • Following tutorials online: https://www.youtube.com/watch?v=pQ1PpcIcHno.
  • Restarting the project.

Relevant information:

  • Platform: .NET Framework 3.5.
  • Things left to do: Uninstall dll packages (I'm not really sure what that means).
ItsPete
  • 2,363
  • 3
  • 27
  • 35
JL-UM
  • 1
  • 1
  • 1
  • You have to use `ExcelReaderFactory.CreateReader()` or `ExcelReaderFactory.CreateOpenXmlReader()`, depending on the Excel file version. `ExcelReaderFactory.Create...()` returns a configured Reader. To create a Reader, pass a Stream object and a New `ExcelReaderConfiguration()` object. Don't use the Interface directly. -- Install the NuGet Packages with the Visual Studio `NuGet Package Manager` (see whether the NuGet version you have supports version `3.3.0` of the package) – Jimi Dec 16 '19 at 22:57
  • Get this Package, too: [ExcelNumberFormat](https://www.nuget.org/packages/ExcelNumberFormat) – Jimi Dec 16 '19 at 22:59
  • https://stackoverflow.com/questions/27634477/using-exceldatareader-to-read-excel-data-starting-from-a-particular-cell/46022604 – Mary Dec 17 '19 at 03:42

1 Answers1

0

I used the following code to run the code, it works well.

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim reader As IExcelDataReader
        Dim stream = File.Open("D:\test.xlsx", FileMode.Open, FileAccess.Read)
        reader = ExcelDataReader.ExcelReaderFactory.CreateReader(stream)
        Dim conf = New ExcelDataSetConfiguration With {
            .ConfigureDataTable = Function(__) New ExcelDataTableConfiguration With {
                .UseHeaderRow = True
            }
        }
        Dim dataSet = reader.AsDataSet(conf)
        Dim dataTable = dataSet.Tables(0)
    End Sub

I noted that we need to install .Net Framework 4.5 to run this program.

enter image description here

Jack J Jun
  • 5,633
  • 1
  • 9
  • 27