PB中可不可以读入EXCEL文件?还有,请问读入的方法用OLE控件和用函数实现有什么不同呢?
------解决方案--------------------
ole方法采用激活excel服务,通过ole自身函数完成
PB自身的ImportFile可以将excel的数据导入到数据窗口中,此种方式不调用excel
如果需要此方面示例,可将邮箱地址发私信给我
------解决方案--------------------
- SQL code
ls_apppath = getcurrentdirectory() if getfileopenname("选择职工工资文件",ls_path,ls_name,'',"EXCEL 文件(*.XLS),*.XLS,DBASE 文件(*.DBF),*.DBF,TXT 文件(*.TXT),*.TXT") <> 1 then return if isnull(li_start) or li_start = 0 then li_start = 1 if right(ls_path,3) = 'xls' or right(ls_path,3) = 'XLS' then objexcel = create oleobject li_result = objexcel.connecttonewobject( "excel.application") if li_result <> 0 then messagebox("信息提示","连接EXCEL失败,请检查计算机中是否安装了EXCEL!") return else objexcel.workbooks.open(ls_path) objexcel.activesheet.cells.copy objexcel.application.visible = false li_err = dw_5.importclipboard(2) //将系统剪切版上的内容粘贴到数据窗口中,其中li_rownum为起始行参数 clipboard("") //清空剪切版上的内容 objexcel.quit() objexcel.disconnectobject() //断开与OLE的连接 destroy objexcel end if elseif right(ls_path,3) = 'txt' or right(ls_path,3) = 'TXT' then li_err = dw_5.importfile(ls_path,li_start) elseif right(ls_path,3) = 'dbf' or right(ls_path,3) = 'DBF' then li_err = dw_5.importfile(ls_path,li_start) end if
------解决方案--------------------
OLEObject ole_excel
ole_excel = CREATE OLEObject
ll_status = ole_excel.ConnectToNewObject("Excel.Application")
ole_excel.Workbooks.Open(filename,True)//打开excel
try
ole_excel.Worksheets('sheet1').Activate
catch(runtimeerror e)
ls_impinfo+=string(now(),'hh:mm:ss')+e.GetMessage() +':无法读取excel的sheet1工作簿!!!~r~n'
FINALLY
string ls_temp
ls_temp = ole_excel.Range("A1").Text//读取数据 excel的A1格
ole_excel.Workbooks.Close
ole_excel.DisconnectObject()
DESTROY ole_excel
------解决方案--------------------
//以下为程序片段,可以参照,不能直接copy,因为一些变量的声明部分没有copy过来
oleobject eole_gg,eole_dp
//打开ole
eole_gg = create oleobject
li_ret = eole_gg.ConnectToNewObject("Excel.Application")
eole_gg.Workbooks.Open(ls_ggwj)
eole_dp = create oleobject
li_ret = eole_dp.ConnectToNewObject("Excel.Application")
eole_dp.Workbooks.Open(ls_dpwj)
//读取excel中数据
s_gg_bh = string(eole_gg.cells(1,2).value)
ls_gg_mc = string(eole_gg.cells(1,3).value)
ldc_gg_spj = dec(eole_gg.cells(ll_row_step,li_gg_spj_col).value)
ll_gg_cjl = long(eole_gg.cells(ll_row_step,li_gg_cjl_col).value)
ldc_gg_kpj = dec(eole_gg.cells(ll_row_step,li_gg_kpj_col).value)
ldc_gg_zdj = dec(eole_gg.cells(ll_row_step,li_gg_zdj_col).value)
ldc_gg_zgj = dec(eole_gg.cells(ll_row_step,li_gg_zgj_col).value)
ldc_gg_cje = dec(eole_gg.cells(ll_row_step,li_gg_cje_col).value)
eole_gg.Workbooks.close()
eole_gg.quit()
destroy eole_gg
eole_dp.Workbooks.close()
eole_dp.quit()
destroy eole_dp