cfc_exceltodw(datawindow adw, string excelname)参数是导出的dw和excel文件的完整路径
OLEObject ole_objectole_object = CREATE OLEObjectinteger li_ret1,valuestring named
li_ret1 = ole_object.ConnectToObject("","Excel.Application")IF li_ret1 = 0 THEN value = MessageBox("提示", "你已打开Excel(注意保存),关闭吗?", Question!, YesNo!)if value = 1 thenole_object.quit()ole_object.disconnectobject()elsereturn 0end ifend if
value = GetFileOpenName("Select File", excelname, named, "XLS", "Excel Files (*.XLS),*.XLS")if value<>1 then return 0end if
li_ret1 = ole_object.ConnectToNewObject("Excel.Application")if li_ret1 <>0 thenMessageBox('提示','OLE无法连接Execl!')return 0end if
openwithparm(w_daopop,1)w_daopop.st_2.text='正在准备......'
ole_object.workbooks.open(excelname)int rtn,i,j
long ll_colnum,ll_rownumstring ls_value
string ls_objects,ls_obj,ls_objs[],ls_objtag[]long ll_pos,ll_len,ll_num = 0,ll_obj[]
ls_objects = trim(adw.Describe('datawindow.Objects'))+"~t"
do while (pos(ls_objects,"~t") > 0)ll_pos = pos(ls_objects,"~t")ll_len = ll_pos - 1ls_obj = left(ls_objects,ll_len)if (adw.Describe(ls_obj + '.type') = 'column' or adw.Describe(ls_obj + '.type') = 'compute') and (adw.Describe(ls_obj + '.band') = 'detail') and (ls_obj <> "asd") thenll_num += 1ls_objs[ll_num] = ls_objls_objtag[ll_num] = adw.Describe(ls_obj + '_t.text')end ifls_objects = right(ls_objects,len(ls_objects) - ll_pos)loop
string str,strtypej=1getremote("r1c1",str,"excel",excelname)str= lower(left(trim(str),len(str)-2))if len(str)=0 thenmessagebox("错误","没有表头数据!")ole_object.quit()ole_object.disconnectobject()destroy ole_objectclose(w_daopop)return 0end if
do while len(str)>0i=1do while lower(trim(ls_objtag[i])) <> str i= i+1if i > ll_num thenmessagebox("错误","没有找到"+str+"列!")ole_object.quit()ole_object.disconnectobject()destroy ole_objectclose(w_daopop)return 0end ifloopll_obj[j]=ij=j + 1getremote("r1c"+string(j),str,"excel",excelname)str= lower(left(trim(str),len(str)-2))loopll_num = j - 1i=2getremote("r"+string(i)+"c1",str,"excel",excelname)str= left(str,len(str)-2)do while len(str)>0ll_rownum=adw.insertrow(0)w_daopop.st_2.text='正在导入第'+string(i - 1)+'条记录......'for j=1 to ll_numgetremote("r"+string(i)+"c"+string(j),str,"excel",excelname)str= left(str,len(str)-2)strtype = adw.Describe( ls_objs[ll_obj[j]] + '.coltype')ll_pos = pos(strtype,"(")if ll_pos<>0 then strtype=left(strtype,ll_pos - 1)CHOOSE CASE strtypeCASE 'number','decimal','long'adw.setitem(ll_rownum,ll_obj[j],dec(str))case 'date'adw.setitem(ll_rownum,ll_obj[j],date(str))case 'datetime'adw.setitem(ll_rownum,ll_obj[j],datetime(date(str)))CASE ELSEadw.setitem(ll_rownum,ll_obj[j],str)END CHOOSEnexti=i+1getremote("r"+string(i)+"c1",str,"excel",excelname)str= left(str,len(str)-2)loopole_object.quit()ole_object.disconnectobject()destroy ole_objectclose(w_daopop)return 1
