oleobject lo_xlapp,lo_xlsub
lo_xlapp = CREATE OLEObject
integer li_ret
string ls_people_id,ls_people_name
integer i,j
string ls_path, ls_filename
integer li_value
long ll_rowcount
li_value = GetFileOpenName("选择文件",ls_path,ls_filename, "xls","EXCEL文件(*.XLS),*.XLS,")
IF li_value=1 THEN
li_ret = lo_xlapp.ConnectToNewObject("Excel.Application")
if li_ret <> 0 then
MessageBox("错误!","无法启动excel程序!")
return
end if
else
MessageBox("错误!","无法打开文件!")
return
end if
//openwithparm(w_message,"正在导入...")
lo_xlapp.application.workbooks.open(ls_path)
lo_xlsub=lo_xlapp.application.activeworkbook.worksheets[1]
ll_rowcount=lo_xlapp.activesheet.usedrange.rows.count
commit;
for i=2 to ll_rowcount
ls_people_id=trim(lo_xlsub.cells[i,1].value) ------Cannot convert oleobject in Any variable to string
ls_people_name=trim(lo_xlsub.cells[i,2].value)
insert into people_store values(integer(ls_people_id),ls_people_name);
//w_message.st_1.text="已经完成:"+string(i - 1)+"/"+string(ll_rowcount)
if sqlca.sqlcode<>0 then
messagebox("提示","失败")
return
end if
next
DESTROY lo_xlapp;
//lo_xlapp.application.workbooks.close(ls_path)
close(w_message)
程序的作用就是把excel导入到数据库。
红色字就是报错的位置,实在没有办法解决,求助阿!
------解决方案--------------------
就是这么写有问题,lo_xlsub.cells[i,1].value 是any型的,不是string的,现在是转换错误!
------解决方案--------------------
由于any型的值不确定,有时候隐式转换会有问题,在使用字符串函数的时候,最好调用函数前强制把要处理的数据转为string类型,否则会有不要预期的错误