前言:
此刻看官们对“vb按行读取文本”都比较关注,朋友们都需要知道一些“vb按行读取文本”的相关文章。那么小编在网络上网罗了一些有关“vb按行读取文本””的相关知识,希望我们能喜欢,朋友们快快来学习一下吧!使用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
'读取数据
Data = ""
For i = 1 To MaxRow
If i > 1 Then Data = Data & vbCrLf
For j = 1 To MaxCol
If j > 1 Then Data = Data & vbTab
Data = Data & DoXLSX.Rs(j, i)
Next
Next
'关闭XLSX文件
DoXLSX.Close
Set DoXLSX = Nothing
MsgBox Data
End Sub
运行
EXCEL文件内容
标签: #vb按行读取文本