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

相关内容

热门资讯

透视透视!hardrock透视... 透视透视!hardrock透视工具,poker master辅助,资料教程(都是存在有挂)-哔哩哔哩...
透视苹果版!wepoker黑侠... 透视苹果版!wepoker黑侠辅助器,sohoo开挂辅助,要领教程(真是有挂)-哔哩哔哩1、不需要A...
透视挂!wepoker私人局辅... 您好,wepoker私人局辅助挂这款游戏可以开挂的,确实是有挂的,需要了解加去威信【13670430...
透视新版!wepoker辅助方... 透视新版!wepoker辅助方法,hhpoker开挂教程,技法教程(一直是有挂)-哔哩哔哩1、每一步...
透视免费!pokeplus脚本... 透视免费!pokeplus脚本,wpk俱乐部辅助器,课程教程(有挂实锤)-哔哩哔哩1、透视免费!po...
透视科技!hhpoker俱乐部... 透视科技!hhpoker俱乐部是干嘛的,hhpoker软件可以玩吗,教程书教程(有挂讲解)-哔哩哔哩...
透视讲解!aapoker公共底... 透视讲解!aapoker公共底牌,wepoker底牌透视,模板教程(有挂教学)-哔哩哔哩1、进入到a...
透视软件!德州局脚本,拱趴大菠... 透视软件!德州局脚本,拱趴大菠萝挂哪里,资料教程(有挂总结)-哔哩哔哩1、玩家可以在拱趴大菠萝挂哪里...
透视辅助!约局吧是否有挂,we... 透视辅助!约局吧是否有挂,wepoker分析,机巧教程(有挂教学)-哔哩哔哩小薇(透视辅助)致您一封...
透视线上!大菠萝手游辅助,hh... 透视线上!大菠萝手游辅助,hhpoker是真的还是假的,攻略教程(有挂教学)-哔哩哔哩1、hhpok...