How to get the contents a particular cell using excel data reader in Visual Basic? Using ExcelData Reader

345 views Asked by At

I'm using the following code and I'm trying to understand how to access the content of each cell in the excel document in order to Validate it... but everything that I've found on the internet is in C# I tried to translate it but I'm getting some errors.. this is my code:

Using stream = File.Open(FullUpldPath, FileMode.Open, FileAccess.Read)
    Using reader As IExcelDataReader = ExcelReaderFactory.CreateReader(stream)
       Dim result As DataSet = reader.AsDataSet(New ExcelDataSetConfiguration() With {
                                                                 .ConfigureDataTable = Function(__) New 
                                                                  ExcelDataTableConfiguration() With {
                                                                 .UseHeaderRow = True}})
       Dim tables As DataTableCollection = result.Tables            
    End Using
End Using
       
1

There are 1 answers

1
MrinmoyeeG On
 Dim file__1 as String = "excelpath" 

 If file__1.EndsWith(".xlsx") Then
                    ' Reading from a binary Excel file (format; *.xlsx)  
                    Dim stream As FileStream = File.Open(file__1, FileMode.Open, FileAccess.Read)
                    excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream)
                    excelReader.IsFirstRowAsColumnNames = True
                    dtExcelData = excelReader.AsDataSet()
                    excelReader.Close()
                    Return dtExcelData
                End If
    
If file__1.EndsWith(".xls") Then
                    ' Reading from a binary Excel file ('97-2003 format; *.xls)  
                    Dim stream As FileStream = File.Open(file__1, FileMode.Open, FileAccess.Read)
                    excelReader = ExcelReaderFactory.CreateBinaryReader(stream)
                    dtExcelData = excelReader.AsDataSet()
                    excelReader.Close()
                    Return dtExcelData
    
                End If