在没有安装office的电脑上,用VB.net代码读取Excel表十几万行的数据?

在没有安装office的电脑上,用VB.net代码读取Excel表十几万行的数据?

引用能读取excel的.net库

这个.NET组件可以做到,https://www.e-iceblue.cn/Introduce/Spire-XLS-NET.html,有免费版,不需要安装office,直接下载这个组件添加到引用里面,代码参考:

Imports System.Collections
Imports System.ComponentModel
Imports Spire.Xls
Imports System.Text
Imports System.IO

Namespace AccessCell
    Partial Public Class Form1
        Inherits Form
        Public Sub New()
            InitializeComponent()
        End Sub
        Private Sub btnRun_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnRun.Click
            '创建Workbook对象
            Dim workbook As New Workbook()

            '从磁盘加载表格文档
            workbook.LoadFromFile("..\..\..\..\..\..\Data\AccessCell.xlsx")

            Dim builder As New StringBuilder()

            '获取第一个工作表
            Dim sheet As Worksheet = workbook.Worksheets(0)

            '按表格名读取表格数据
            Dim range1 As CellRange = sheet.Range("A1")
            builder.AppendLine("Value of range1: " & range1.Text)

            '按行列读取表格数据
            Dim range2 As CellRange = sheet.Range(2,1)
            builder.AppendLine("Value of range2: " & range2.Text)

            '按表格集读取表格数据
            Dim range3 As CellRange = sheet.Cells(2)
            builder.AppendLine("Value of range3: " & range3.Text)

            '保存数据到txt文件
            Dim result As String="AccessCell_out.txt"
            File.WriteAllText(result, builder.ToString())

            '打开txt文件
            OutputViewer(result)
        End Sub
        Private Sub OutputViewer(ByVal fileName As String)
            Try
                Process.Start(fileName)
            Catch
            End Try
        End Sub

        Private Sub btnClose_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnClose.Click
            Close()
        End Sub

    End Class
End Namespace
Namespace AccessCell
    Friend NotInheritable Class Program
        ''' <summary>
        ''' The main entry point for the application.
        ''' </summary>
        Private Sub New()
        End Sub
        <STAThread>
        Shared Sub Main()
            Application.EnableVisualStyles()
            Application.SetCompatibleTextRenderingDefault(False)
            Application.Run(New Form1())
        End Sub
    End Class
End Namespace