【已解决】双循环出错,为什么只循环一层呢?
本帖最后由 ap112 于 2014-5-30 16:39 编辑#include <Excel.au3>
$sFilePath1 = "D:\sgmuserprofile\dong hongfei\Desktop\1.xls" ;打开EXCEL文件
$oExcel = _ExcelBookAttach($sFilePath1)
If @error = 1 Then
MsgBox(0, "错误!", "无法创建对象!")
Exit
ElseIf @error = 2 Then
MsgBox(0, "错误!", "文件不存在!")
Exit
EndIf
$hang = InputBox("提示", "输入你要获取多少行数据:", "1")
Global $EX
$j=0
If $hang < 1 Then
MsgBox("","","输入错误!")
Exit
Else
For $i = 1 To $hang Step +1
Do
$j=$j+1
$EX[$i][$j] = _ExcelReadCell($oExcel,$i,$j)
MsgBox(0, "",$EX[$i][$j])
Until $j=6
ExitLoop
Next
EndIf If $hang < 1 Then
MsgBox("","","输入错误!")
Exit
Else
For $i = 1 To $hang Step +1
Do
$j=$j+1
$EX[$i][$j] = _ExcelReadCell($oExcel,$i,$j)
MsgBox(0, "",$EX[$i][$j])
Until $j=6
Next
EndIf
这样也不行,换成双For也不行?????{:face (382):} #include <Excel.au3>
$sFilePath1 = "D:\sgmuserprofile\dong hongfei\Desktop\1.xls" ;打开EXCEL文件
$oExcel = _ExcelBookAttach($sFilePath1)
If @error = 1 Then
MsgBox(0, "错误!", "无法创建对象!")
Exit
ElseIf @error = 2 Then
MsgBox(0, "错误!", "文件不存在!")
Exit
EndIf
$hang = InputBox("提示", "输入你要获取多少行数据:", "1")
Global $EX
If $hang < 1 Then
MsgBox("","","输入错误!")
Exit
Else
with $oExcel.activesheet.usedrange
$EX=.cells(1,1).resize($hang,.columns.count).value
end with
EndIf这样试下,不过行列是反的,如果存在一个单元格的情况,还要判断一下isarray($EX) 回复 3# kevinch
$EX 中没获取到值呀?试了不行。我是想把Excel逐行读取数据,并输出来。 为什么没人回呀? 很急呀!大神来帮帮我吧 本帖最后由 shqf 于 2014-5-30 16:19 编辑
出错信息看了吗?是哪一句出错了?
“$EX[$i][$j] = _ExcelReadCell($oExcel, $i, $j)
^ ERROR”
这说明 是这一句中的$EX[$i][$j] 出错了。不是循环出错啊,是超出数组定义的大小!
Global $EX改成Global $EX,ExitLoop是不能有的。 回复 7# shqf
谢谢! 已解决
页:
[1]