不需安装Excel即可使用VB.NET读取Excel文件
创始人
2025-01-10 11:30:05
0
  1. 使用Open XML SDK:

代码示例:

Using spreadsheetDocument__1 As SpreadsheetDocument = SpreadsheetDocument.Open(path, False) Dim workbookPart As WorkbookPart = spreadsheetDocument__1.WorkbookPart Dim sheet As Sheet = workbookPart.Workbook.Descendants(Of Sheet)().FirstOrDefault() Dim worksheet As Worksheet = DirectCast(workbookPart.GetPartById(sheet.Id.Value), WorksheetPart).Worksheet

  For Each row As Row In worksheet.Descendants(Of Row)()
       For Each cell As Cell In row.Descendants(Of Cell)()
            ' Do something with the cell value here...
       Next
  Next

End Using

  1. 使用OleDb连接:

代码示例:

Dim connectionString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" & path & ";Extended Properties=Excel 12.0;" Dim adapter As New OleDbDataAdapter("SELECT * FROM [Sheet1$]", connectionString) Dim ds As New DataSet() adapter.Fill(ds)

' Use the dataset here...

但此方法仅适用于2007及以上版本的Excel文件。如需使用2003及以下版本的Excel文件,需要将连接字符串中的“Excel 12.0”更改为“Excel 8.0”。

相关内容

热门资讯

透视线上!wepoker透视脚... 透视线上!wepoker透视脚本苹果版,wepoker辅助脚本,细节揭秘(都是有挂);原来确实真的有...
透视安装!aapoker辅助工... 透视安装!aapoker辅助工具免费下载,hh poker辅助有用吗,攻略教程(原本真的是有挂);人...
透视安装!aapoker辅助插... 透视安装!aapoker辅助插件工具下载,wepoker透视脚本是什么,透牌教程(往昔是真的有挂);...
透视挂透视!wepoker辅助... 透视挂透视!wepoker辅助工具,poker红龙辅助,辅助教程(素来存在有挂);科技详细教程Q群《...
透视黑科技!wpk辅助工具下载... 透视黑科技!wpk辅助工具下载,德扑圈透视,黑科技教程(原先有挂)关于wpk辅助工具下载机制的,其中...
透视新版!德普之星透视辅助io... 透视新版!德普之星透视辅助ios,pokermaster修改器,透视教程(总是是有挂);原来确实真的...
透视辅助!wepoker脚本下... 透视辅助!wepoker脚本下载,wepoker游戏下载,插件教程(本然真的是有挂)1、许多玩家不知...
透视规律!wepoker透视,... 透视规律!wepoker透视,hhpoker透视工具,AI教程(原来是真的有挂);原来确实真的有挂(...
透视数据!hhpoker开辅助... hhpoker开辅助软件新手教程相关信息汇总(需添加指定Q群1067239143获取下载链接);透视...
透视新版!hhpoker透视功... 透视新版!hhpoker透视功能如何下载,hh poker透视器下载,黑科技教程(一直是真的有挂);...