查询excel遇到问题请求高手帮助?

遇到了问题?请先进行搜索(中文和英文),然后在此提问
gongnl
Posts: 72
Joined: 05 Jan 2015, 03:57
Location: /gongnltmp/

查询excel遇到问题请求高手帮助?

23 Nov 2017, 22:15

我写了一个查询excel工作表内容的脚本如下,两台电脑Autohotkey都默认安装Unicode 32bit,在一台电脑上双击脚本可正常查询到结果,在另一台电脑一定要右键脚本选择打开方式选择AutoHotkeyA32.exe打开,才能查询到结果,否则如果双击打开运行搜索到的记录数为0,请教高手是什么原因,是电脑系统哪没有设置好,请高手不吝赐教,谢谢!!!

Code: Select all

objConnection := ComObjCreate("ADODB.Connection")
objRecordSet := ComObjCreate("ADODB.Recordset")

dataSource := A_ScriptDir . "\swsr123.xlsm"
objConnection.Open("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='"
dataSource "';Extended Properties='Excel 12.0 Macro;HDR=No;IMEX=1';")

adOpenStatic := 1
adLockOptimistic := 1
adCmdText := 1
sqlstr  := "Select * FROM [Data$] where f1 Like '%abcd efg123%'"

try objRecordset.Open(sqlstr, objConnection, adOpenStatic,
adLockOptimistic)
catch e{
   MsgBox, 执行select查询出错!
return
}

rn :=  objRecordset.RecordCount
MsgBox,  Excel中搜索到的记录数rn= %rn%

objRecordset.close
objConnection.Close
return

Return to “请求帮助”

Who is online

Users browsing this forum: No registered users and 7 guests