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

相关内容

热门资讯

科普常识!aapoker发牌逻... 科普常识!aapoker发牌逻辑,拱趴大菠萝万能挂图解,透明挂教程(有挂技巧);人气非常高,ai更新...
透视攻略!wepoker怎么拿... 透视攻略!wepoker怎么拿到好牌(透视)真是有挂(详细辅助揭秘教程)一、AI软件牌型概率发牌机制...
2分钟细说!wepoker游戏... 1、2分钟细说!wepoker游戏的安装教程,wepoker透视脚本,必赢教程(有挂透明)2、进入游...
透视美元局!pokernow辅... 透视美元局!pokernow辅助控制(透视)原来是有挂(详细辅助微扑克教程);进入游戏-大厅左侧-新...
热门推荐!wepokerplu... 1、热门推荐!wepokerplus辅助,hhpkoer辅助器视频,总结教程(有挂神器)2、进入游戏...
透视美元局!悦扑克脚本(透视)... 透视美元局!悦扑克脚本(透视)都是是有挂(详细辅助安装教程);1、进入到黑科技之后,能看到左侧胜局榜...
2分钟细说!wepoker怎么... 自定义竞技联盟透视插件系统规律,只需要输入自己想要的开挂功能,一键便可以生成出微扑克专用辅助器,不管...
透视最新!aapoker破解侠... 透视最新!aapoker破解侠是真的吗(透视)切实真的是有挂(详细辅助切实教程)1、超多福利:超高返...
透视智能ai!wepoker透... 透视智能ai!wepoker透视挂底牌(透视)都是真的有挂(详细辅助教你攻略);运wepoker透视...
一分钟秒懂!pokermast... 一分钟秒懂!pokermaster破解版,wepoker养号规律,2025新版教程(有挂教程);实战...