本帖最后由 jj119120 于 2021-10-7 17:32 编辑
先上代码,运行后点搜索,显示数组那里看不到具体内容全是array,但如果_ArrayDisplay($aResult1,"显示数组","","64")改为_ArrayDisplay($aResult1[0],"显示数组","","64")却又能正确显示,但只能显示一个结果,不知道哪里出错了
配合使用的excel表格https://www.lanzouw.com/ipPvFv0zpub#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <Array.au3>
#include <Excel.au3>
#include <MsgBoxConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 324, 40, 459, 157)
$Input1 = GUICtrlCreateInput("关于", 8, 8, 225, 21, $ES_MULTILINE, $WS_EX_ACCEPTFILES)
GUICtrlSetState($Input1, $GUI_DROPACCEPTED)
$Button1 = GUICtrlCreateButton("搜索", 240, 8, 73, 21)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
Local $oExcel = _Excel_Open(False, False, False, False, True)
Local $oWorkbook = _Excel_BookOpen($oExcel, @ScriptDir & "\特种作业考试题库题库.xls")
Local $xinzuobiao0, $xinzuobiao,$j
Global $aResult1[30]
While 1
$nMsg = GUIGetMsg()
Switch $nMsg
Case $GUI_EVENT_CLOSE
_Excel_Close($oExcel, False, True);关闭EXCEL
Exit
Case $Button1
cl()
EndSwitch
WEnd
Func cl()
$neirong = GUICtrlRead($Input1);处理$Input1的内容以便搜索
$aResult = _Excel_RangeFind($oWorkbook, $neirong);查找EXCEL
$j=UBound($aResult) - 1;获取最大值
For $h = 0 To $j;从0到最大值
$xinzuobiao0 = StringReplace($aResult[$h][2], "$", "");获取单元格地址,并去掉$
$xinzuobiao = $xinzuobiao0 & ":" & StringReplace($xinzuobiao0, StringLeft($xinzuobiao0, 1), "I");单元格地址范围
$aResult1[$h] = _Excel_RangeRead($oWorkbook, 1, $xinzuobiao);读取指定单元格地址范围的内容
Next
_ArrayDisplay($aResult1,"显示数组","","64");显示数组
EndFunc ;==>cl
|