需要将XLConst包含且load进来,再对相应的键值如‘LookAt’赋值,详见如下代码:
require 'win32ole'
def class XLConst
end
def main()
excel=WIN32OLE.new("excel.application");
excel['Visible']=false;
excel['DisplayAlerts']=false;
WIN32OLE.const_load(excel,XLConst);
wb=excel.workbooks.open("xxx\xxx\xxx.xls");
ws=wb.worksheets(1);
searchInfo="xxx";
#搜索字符串,全匹配
#rs=ws.range("A1:A1000").find(searchInfo.value.to_s,'LookAt'=>XLConst::XlWhole);
#搜索数字,全匹配
rs=ws.range("A1:A1000").find(searchInfo.value.to_i.to_s,'LookAt'=>XLConst::XlWhole);
if (rs == nil)
printf("[row%s]:%s",rs.row,rs.value);
end
excel.Quit();
excel=nil;
GC.start;
end
main