用VB读取EXCEL中的数据
我想读取d:\sss.xls中sheet1A3:C5的数据,在TXT文本框中显示为A3A4A5B3B4B5C3C4C5该怎么写?自己的代码:OnErrorResumeNe...
我想读取d:\sss.xls 中sheet1 A3:C5的数据,在TXT文本框中显示为
A3 A4 A5
B3 B4 B5
C3 C4 C5
该怎么写?
自己的代码:
On Error Resume Nexe
Set xlBook = xlApp.Workbooks.Open("d:\sss.xls")
xlApp.Visible = False
Set xlSheet = xlBook.Sheets("sheet1")
xlSheet.Select
Text1.Text = ""
Dim a(3, 3) As Intege
For i = 1 To 3
For j = 1 To 3
a(i, j) = Int(xlSheet.Range("A3"))
Next j, i
For i = 1 To 3
For j = 1 To 3
Text1.Text = Text1.Text + Str(a(i, j)) + " "
Next j
Text1.Text = Text1.Text + vbNewLine
Next i
显示的结果全是A3的值,怎么修改啊。 展开
A3 A4 A5
B3 B4 B5
C3 C4 C5
该怎么写?
自己的代码:
On Error Resume Nexe
Set xlBook = xlApp.Workbooks.Open("d:\sss.xls")
xlApp.Visible = False
Set xlSheet = xlBook.Sheets("sheet1")
xlSheet.Select
Text1.Text = ""
Dim a(3, 3) As Intege
For i = 1 To 3
For j = 1 To 3
a(i, j) = Int(xlSheet.Range("A3"))
Next j, i
For i = 1 To 3
For j = 1 To 3
Text1.Text = Text1.Text + Str(a(i, j)) + " "
Next j
Text1.Text = Text1.Text + vbNewLine
Next i
显示的结果全是A3的值,怎么修改啊。 展开
展开全部
Dim a(3, 3) As Intege
For i = 1 To 3
For j = 1 To 3
'这步是利用A到C之间的ASCII码来处理,如果是i循环1,5的话,那就会是A,B,C,D,E,内循环j管A3~A5,
a(i, j) = Int(xlSheet.Range(chr(asc("A")+i-1)) & Cstr(j+2))
Next j, i
For i = 1 To 3
For j = 1 To 3
'这步是利用A到C之间的ASCII码来处理,如果是i循环1,5的话,那就会是A,B,C,D,E,内循环j管A3~A5,
a(i, j) = Int(xlSheet.Range(chr(asc("A")+i-1)) & Cstr(j+2))
Next j, i
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim a(1 to 3, 1 to 3) As Intege
For i = 1 To 3
For j = 1 To 3
a(j,i) = Int(xlSheet.cells(i,j))
Next j,i
For i = 1 To 3
For j = 1 To 3
a(j,i) = Int(xlSheet.cells(i,j))
Next j,i
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
a(i, j) = Int(xlSheet.Range("A3")) 中 xlSheet.Range("A3") 没改变,当然都是 A3
可以写成xlSheet.cell(行数值i,列数值j) i 跟j 根据for改变
可以写成xlSheet.cell(行数值i,列数值j) i 跟j 根据for改变
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询