如何用OLE将EXCEL导入DATAWINDOW中? // Long value,Ll_col,Ll_01,Ll_row String Ls_path,Ls_filename,Ls_cx Is_syspath=space(255) GetCurrentDirectoryA(255,Is_syspath) value=GetFileopenname("请选择要导入BOM的EXECL类型文件!",ls_path,ls_filename,'xls','EXECL 文件(*.xls),*.xls') is_filename = mid(ls_filename,1,len(ls_filename) - 4) if value <> 1 then 没取到、或者取消返回 Return false end if if luo_excel.connecttoobject("","Excel.Application") <> 0 then if luo_excel.ConnectToNewObject("Excel.Application") <> 0 then messagebox(gs_tsxx,'连接excel失败请稍后再试!') return false end if end if SetPointer(HourGlass!) luo_excel.workbooks.open(ls_path) luo_sub = luo_excel.application.workbooks(ls_filename).worksheets(1) /// 取出数据区域 ll_col=2 do while 1=1 luo_sub.cells(ll_col,1).copy() tab_1.tabpage_1.sle_2.paste() ls_cx=trim(tab_1.tabpage_1.sle_2.text) if trim(tab_1.tabpage_1.sle_2.text)="" or isnull(tab_1.tabpage_1.sle_2.text) then exit end if tab_1.tabpage_1.sle_2.text='' ll_col++ loop //Ll_col 记录总的行数 if ll_col<2 then goto out//空的Excel, //删除PIM_BOM表中原有数据 delete from inv_usedquota2; tab_1.tabpage_1.dw_8.reset() tab_1.tabpage_1.dw_8.retrieve() 取数 ll_01=2 //从第三行开始取数 do while ll_01<= ll_col - 1 ll_row=tab_1.tabpage_1.dw_8.insertrow(0) tab_1.tabpage_1.sle_2.text='' luo_sub.cells(ll_01,1).copy() tab_1.tabpage_1.sle_2.paste() ls_cx=trim(tab_1.tabpage_1.sle_2.text) if left(ls_cx,1)='"' then ls_cx=right(ls_cx,len(ls_cx) - 1) end if tab_1.tabpage_1.sle_2.text='' tab_1.tabpage_1.dw_8.setitem(ll_row,'wlh',ls_cx) luo_sub.cells(ll_01,2).copy() tab_1.tabpage_1.sle_2.paste() ls_cx=trim(tab_1.tabpage_1.sle_2.text) tab_1.tabpage_1.sle_2.text='' tab_1.tabpage_1.dw_8.setitem(ll_row,'zwlh',ls_cx) luo_sub.cells(ll_01,5).copy() tab_1.tabpage_1.sle_2.paste() ls_cx=trim(tab_1.tabpage_1.sle_2.text) if left(ls_cx,1)='"' then ls_cx=right(ls_cx,len(ls_cx) - 1) end if tab_1.tabpage_1.sle_2.text='' tab_1.tabpage_1.dw_8.setitem(ll_row,'de',dec(ls_cx)) luo_sub.cells(ll_01,9).copy() tab_1.tabpage_1.sle_2.paste() ls_cx=trim(tab_1.tabpage_1.sle_2.text) if left(ls_cx,1)='T' or left(ls_cx,1)='t' then ls_cx='1' else ls_cx='0' end if tab_1.tabpage_1.sle_2.text='' tab_1.tabpage_1.dw_8.setitem(ll_row,'fjbs',integer(ls_cx)) ll_01++ loop out: luo_excel.application.workbooks(ls_filename).close(false) luo_excel.application.quit() luo_excel.disconnectobject() ///向数据库提交数据 if tab_1.tabpage_1.dw_8.update() = 1 then commit; else messagebox('',sqlca.sqlerrtext) rollback; Return false end if return true
如何用OLE将EXCEL导入DATAWINDOW中?
最新推荐文章于 2024-08-15 23:35:23 发布