VB.NET 操作EXCEL数据操作ExcelDataReader库

转载软件 · 2023-11-08 · 352 人浏览

代码测试可用,使用这个库的操作还是不错的。

Dim filePath As String = "E:\1.xlsx"

' 创建一个文件流来打开Excel文件
Using stream As FileStream = File.Open(filePath, FileMode.Open, FileAccess.Read)

    ' 使用ExcelDataReader打开Excel文件
    Using reader As IExcelDataReader = ExcelReaderFactory.CreateReader(stream)

        ' 选择要读取的工作表,默认为第一个工作表
        reader.Read()

        ' 循环读取每一行的第二列的值
        While reader.Read()
            Dim value As Object = reader.GetValue(1) ' 第二列的索引为1
            Console.WriteLine(value.ToString()) ' 打印第二列的值
        End While
    End Using
End Using
VB.NET