vb.net 如何读取excel数组
时间: 2023-10-13 22:22:59 浏览: 115
你可以使用 Microsoft.Office.Interop.Excel 库来读取 Excel 数组。下面是一个简单的例子:
```vb.net
Imports Microsoft.Office.Interop.Excel
' 创建 Excel 应用程序对象
Dim excelApp As New Application()
' 打开 Excel 文件
Dim workbook As Workbook = excelApp.Workbooks.Open("C:\example.xlsx")
' 选择工作表
Dim worksheet As Worksheet = workbook.Sheets(1)
' 获取工作表范围
Dim range As Range = worksheet.UsedRange
' 获取数组
Dim data As Object(,) = range.Value
' 关闭 Excel 文件
workbook.Close()
excelApp.Quit()
' 输出数组
For i As Integer = 1 To data.GetLength(0)
For j As Integer = 1 To data.GetLength(1)
Console.Write(data(i, j) & vbTab)
Next
Console.WriteLine()
Next
```
在这个例子中,我们首先创建了一个 Excel 应用程序对象,然后打开了一个 Excel 文件,并选择了第一个工作表。然后,我们获取了工作表的范围,并将其值存储在一个二维对象数组中。最后,我们输出了这个数组的内容。
请注意,这个例子假设你已经安装了 Microsoft Office 并且已经添加了对 Microsoft.Office.Interop.Excel 库的引用。
阅读全文
相关推荐


















