使用XLSXApp对象读取XLSX文件,Sheet1的文本内容
打开工程,添加按钮,标题改成测试
双击按钮,添加如下代码
Private Sub Command1_Click()
Dim DoXLSX As XLSXApp
Dim MaxRow As Integer
Dim MaxCol As Integer
Dim i As Integer
Dim j As Integer
Dim Data As String
Dim Error As String
Set DoXLSX = New XLSXApp
'打开XLSX文件
If DoXLSX.Open("Test1.xlsx", Error) = False Then
MsgBox Error
Set DoXLSX = Nothing
Exit Sub
End If
'选择Sheet1
If DoXLSX.SelSheet("Sheet1", Error) = False Then
DoXLSX.Close
Set DoXLSX = Nothing
MsgBox Error
Exit Sub
End If
'读取Excel行和列信息
MaxRow = DoXLSX.GetRowTotal
MaxCol = DoXLSX.GetColumnCount
If MaxRow = 0 Or MaxCol = 0 Then
DoXLSX.Close
Set DoXLSX = Nothing
MsgBox "没有数据!"
Exit Sub
End If
'读取数据
Datahttps://www.itzhengshu.com/excel/= ""
For i = 1 To MaxRow
If i > 1 Then Data = https://www.itzhengshu.com/excel/Data & vbCrLf
For j = 1 To MaxCol
If j > 1 Then Data = https://www.itzhengshu.com/excel/Data & vbTab
Data = https://www.itzhengshu.com/excel/Data & DoXLSX.Rs(j, i)
Next
Next
'关闭XLSX文件
DoXLSX.Close
Set DoXLSX = Nothing
MsgBox Data
End Sub