急问:pb中关于excel的ole属性以及函数调用!!
哪里可以查到OLEObject的属性、函数等的帮助!!非常急!
其实目前急用的就是如何打开一个已有的excel文档,然后激活某个sheet,再取激活的页面中的数据,放入到dw中。
但是下面的程序总报错(具体错误地方已标注),请高手指点!!急!!!!
//open excel file
lo_excel = create OLEObject
li_value = getfileopenname("excel file",ls_path,ls_file,"excel文件","excel,*.xls")
if li_value = 1 then
li_excelok = lo_excel.connecttoobject(ls_path)
if li_excelok <> 0 then
messagebox("","连接EXCEL失败,请检查计算机中是否安装了EXCEL!")
return -1
end if
lo_excel.Application.WorkBooks.open(ls_path)
// lo_excel.WorkSheets('Sheet1').Activate//这一句是行不通的,但是网上很多人的例子用这个,迷惑......
end if
ib_end = false
if this.event ue_connect() = -1 then return -1
dw_cardinfo.setredraw(false)
//get data
for i = 1 to 9999
ll_row = dw_cardinfo.insertrow(0)
for j = 1 to 5
li_row = j - 1
lo_excel.Application.ActiveWorkBook.WorkSheets(1).Cells(1,1).value = "test"//测试用,行不通,网上很多人给的例子是用这个,疑惑中......
ls_tmp = lo_excel.Application.ActiveWorkBook.WorkSheets(1).Cells(1,1) //报错,同上一句
// ls_keyvalue[li_row] = String(lo_excel.Application.ActiveWorkbook.Worksheets[1].cells[i,j]) 本句行不通,疑惑中......
// ls_tmp = lo_excel.cells(i,j)//报错。
ls_keyvalue[li_row] = ls_tmp
if isnull(ls_keyvalue[li_row]) or len(ls_keyvalue[li_row]) <= 0 then
if j <> 0 then
messagebox("message","数据源文件中有空字符,请查证后重新导入~~d第"+string(i)+"行 第"+string(j)+"列")
return -1
else
ib_end = true
end if
end if
next
if ib_end then exit
//赋值语句省略
next
lo_excel.DisconnectObject()
destroy lo_excel