資源描述:
《PB數(shù)據(jù)窗口導(dǎo)出excel.doc》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、PB數(shù)據(jù)窗口導(dǎo)出excel,修改第一行英文標(biāo)題為中文標(biāo)題,計算合計值分類:PB2013-11-0513:01712人閱讀評論(0)收藏舉報pb數(shù)據(jù)窗口導(dǎo)出excel中文標(biāo)題計算合計值1.PB數(shù)據(jù)窗口導(dǎo)出excel利用dw.saveas(filename,Excel5!,true)方法先導(dǎo)出帶英文標(biāo)題的excel。intli_retstringls_filename,ls_pathnamebooleanlb_existifdw.rowcount()=0then?messagebox("提示","無可保存的數(shù)據(jù)!")?return;endifli_
2、ret=GetFileSaveName("保存文件",ls_pathname,ls_filename,"xls","Excel文件(.xls),.xls")ifli_ret=1then?lb_exist=FileExists(ls_pathname)?IFlb_existTHEN??li_ret=MessageBox("保存",ls_pathname+"已經(jīng)存在,是否覆蓋?",Exclamation!,YesNo!)?endif?ifli_ret=1then??li_ret=dw.saveas(ls_pathname,EXCEL5!,true)
3、//此處必須為true,后面要修改第一行。??ifli_ret=1then???//修改標(biāo)題頭,計算合計???gf_set_title_sum(dw,ls_pathname)???messagebox('提示','保存成功!')??endif?endifendif2.修改第一行英文標(biāo)題為中文標(biāo)題,計算合計值gf_set_title_sum(datawindowdw,stringvs_filename)函數(shù)如下:intli_retlongll_column,ll_num,ll_dwrowcountlongll_xlsrowcount//excel
4、的行數(shù)stringls_objtag[]//標(biāo)題stringls_width[]//每列寬度stringls_obj,ls_valuestringls_objs[]inti,jStringls_english="ABCDEFGHIJKLMNOPQRSTUVWXYZ"stringls_colname//操作excelPointeroldpointerOLEObjectole_objectole_object=CREATEOLEObject//修改標(biāo)題頭,計算合計li_ret=ole_object.ConnectToNewObject("Excel
5、.Application")IFli_ret<>0THEN?MessageBox('打開錯誤','無法連接EXCEL!是否已經(jīng)安裝了EXCEL?錯誤號:'+String(li_ret))?RETURNENDIFole_object.Visible=false??//ole應(yīng)用服務(wù)是否顯示oldpointer=SetPointer(HourGlass!)ole_object.application.workbooks.open(vs_filename)//打開文件//獲取標(biāo)題ll_column=Long(dw.Object.DataWindow.
6、Column.Count)//取得字段總數(shù)i=0FORll_num=1TOll_column?IFdw.DESCRIBE("#"+String(ll_num)+".Visible")="1"THEN//列標(biāo)志為nun_Visible的不顯示??i=i+1?ls_obj=dw.DESCRIBE("#"+String(ll_num)+".name")//字段名稱的實(shí)際存儲值?ls_objs[i]=ls_obj?ls_objtag[i]=dw.DESCRIBE(ls_obj?+"_t.text")?//字段名稱的顯示值?ls_width[i]?=dw
7、.DESCRIBE(ls_obj?+'.width')??//每列的寬度?ENDIFNEXT//開始修改標(biāo)題頭forj=1toupperbound(ls_objtag)?ole_object.Cells(1,j).value=ls_objtag[j]next//標(biāo)題一行居中ole_object.rows(1).HorizontalAlignment=3//居中//計算合計值ll_dwrowcount=dw.rowcount()//行數(shù)ll_xlsrowcount=ll_dwrowcount+1//除了合計之外的行數(shù)ole_object.cell
8、s(ll_xlsrowcount+1,1).value='合計'forj=2toll_column?ls_colname=Mid(ls_english