不需安装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”。

相关内容

热门资讯

透视安装!pokemmo脚本辅... 透视安装!pokemmo脚本辅助器,wepoker有没有透视方法,2025新版教程(有挂技巧);1、...
透视工具!wepoker辅助工... 透视工具!wepoker辅助工具,wepoker辅助器安装包定制(透视)总结教程(有挂脚本);小薇(...
透视挂!wepoker透视脚本... 透视挂!wepoker透视脚本安卓,德扑HHpoker有挂吗,透视教程(有挂方法);1、下载好wep...
透视最新!wepoker怎么设... 透视最新!wepoker怎么设置盖牌,wepoker私人局辅助(透视)攻略方法(有挂黑科技)1、许多...
透视苹果版!xpoker辅助工... 透视苹果版!xpoker辅助工具,pokernow辅助工具,wepoke教程(有挂详情)1、每一步都...
透视攻略!wepoker有插件... 透视攻略!wepoker有插件吗,wepoker究竟有没有透视(透视)揭秘攻略(有挂规律)进入游戏-...
透视规律!约局吧德州可以透视吗... 透视规律!约局吧德州可以透视吗,黑侠破解wepoker,AI教程(有挂详情);1、进入游戏-大厅左侧...
透视app!wepoker免费... 透视app!wepoker免费脚本,wepoker轻量版透视(透视)教你攻略(有挂技巧)1、进入游戏...
透视玄学!hhpoker辅助挂... 透视玄学!hhpoker辅助挂是真的吗,wepoker究竟有没有透视,揭秘教程(有挂内幕);亲,关键...
透视数据!wepoker游戏安... 透视数据!wepoker游戏安装教程,wepoker透视脚本安卓(透视)透明挂教程(有挂插件);1、...