PB-數(shù)據(jù)窗口數(shù)據(jù)導(dǎo)出到word文件中_第1頁(yè)
PB-數(shù)據(jù)窗口數(shù)據(jù)導(dǎo)出到word文件中_第2頁(yè)
PB-數(shù)據(jù)窗口數(shù)據(jù)導(dǎo)出到word文件中_第3頁(yè)
PB-數(shù)據(jù)窗口數(shù)據(jù)導(dǎo)出到word文件中_第4頁(yè)
PB-數(shù)據(jù)窗口數(shù)據(jù)導(dǎo)出到word文件中_第5頁(yè)
已閱讀5頁(yè),還剩4頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

PB數(shù)據(jù)窗口數(shù)據(jù)導(dǎo)出到word,excel博客分類:powerbuilderExcelJ#WindowsPB數(shù)據(jù)窗口數(shù)據(jù)導(dǎo)出到word,excel,excel可以自定義修改excel文檔的列寬對(duì)齊方式,字體樣式等//dwsave2word調(diào)用oleglobaltypegf_exportdata2wordfromfunction_objectendtypeforwardprototypesglobalsubroutinegf_exportdata2word(datawindowad_datawindow)endprototypesglobalsubroutinegf_exportdata2word(datawindowad_datawindow);stringls_filepathls_filepath=gf_getfilesavename()OleObjectOleObjectWordOleObjectWord=CreateOleObject//連接wordifOleObjectWord.ConnectToNewObject("Word.application")<>0thenMessagebox("提示","ole連接錯(cuò)誤!")returnendifOleObjectWord.visible=false//word文檔在操作數(shù)據(jù)過程中是否可見Longcol_colnum,col_rownumConstantLongwdTableBehavior=1ConstantLongwdAutoFitFixed=0ConstantLongwdCell=12Stringstr_value//得到數(shù)據(jù)窗口數(shù)據(jù)的列數(shù)和行數(shù)(行數(shù)應(yīng)該是數(shù)據(jù)行數(shù)+1)col_colnum=Long(ad_datawindow.object.datawindow.column.count)col_rownum=ad_datawindow.rowcount()+1//先在word文檔中畫好表格SetPointer(HourGlass!)OleObjectWord.Documents.AddOleObjectWord.ActiveDocument.Tables.Add(OleObjectWord.Selection.Range,&+col_rownum,col_colnum,wdTableBehavior,wdAutoFitFixed)stringls_colnameintegeri,j,k,lfori=1tocol_colnum//得到標(biāo)題頭的名稱ls_colname=ad_datawindow.Describe('#'+string(i)+".name")+"_t"strvalue=ad_datawindow.DEscribe(ls_colname+".text")OleObjectWord.Selection.TypeText(str_value)OleObjectWord.Selection.MoveRight(wdCell)Nextad_datawindow.setRedraw(false)OleObjectWord.Selection.MoveLeft(wdCell)SetPointer(HourGlass!)fori=2tocol_rownumforj=1tocol_colnumad_datawindow.Scrolltorow(i-1)ad_datawindow.SetColumn(j)strvalue=ad_datawindow.GetItemstring(i-1,j)ifisnull(str_value)thenstrvalue=''endifOleObjectWord.Selection.MoveRight(wdCell)OleObjectWord.Selection.TypeText(str_value)nextnextad_datawindow.setredraw(true)ConstantlongwdFormatDocument=0//保存新建的文檔OleObjectWord.ActiveDocument.SaveAs(ls_filepath,0,false,"",true,"",false,false,false,false,false)booleanlb_existlb_exist=FileExists(ls_filepath)iflb_existthenmessagebox("提示","數(shù)據(jù)已經(jīng)保存到"+ls_filepath)endif//斷開ole連接OleObjectWord.DisconnectObject()destroyOleObjectWordendsubroutine//dwsave2xls調(diào)用oleglobaltypegf_dwsavetoexcelfromfunction_objectendtypeforwardprototypesglobalfunctionintegergf_dwsavetoexcel(datawindowadw)endprototypesglobalfunctionintegergf_dwsavetoexcel(datawindowadw);stringxlsname,namedintegervaluestringcol_del,first_delvalue=GetFileSaveName("另存為",xlsname,named,"XLS","XlsFiles(*.XLS),*.XLS")ifvalue=1thenadw.saveas(xlsname,Excel!,TRUE)elsereturn2endifconstantintegerppLayoutBlank=12OLEObjectole_objectole_object=CREATEOLEObjectintegerli_retli_ret=ole_object.ConnectToObject("","Excel.Application")IFli_ret<>0THENli_ret=ole_object.ConnectToNewObject("Excel.Application")IFli_ret<>0THENmessagebox("OLE錯(cuò)誤","OLE無法連接!~r~n錯(cuò)誤號(hào):"+string(li_ret))Return0ENDIFole_object.visible=FalseENDIFpointeroldpointeroldpointer=SetPointer(HourGlass!)ole_object.Workbooks.open(xlsname)ole_object.WorkSheets[1].Activatelongcolumncount,rowscountcolumncount=long(adw.object.datawindow.column.count)rowscount=adw.rowcount()+1stringls_colname[],ls_valueintegeri,jlonghandlehandle=OpenChannel("Excel",xlsname)//將列名轉(zhuǎn)化為中文名稱,即標(biāo)題頭名稱forj=1tocolumncountls_colname[j]=adw.describe("#"+string(j)+".name")ls_value=adw.describe(ls_colname[j]+"_t"+".text")//ole_object.activesheet.cells[1,j].value=ls_value開始的方法SetRemote("R1C"+STRING(J),ls_value,handle)nextdatawindowchildldw_childlongll_foundForj=1Tocolumncount//col_del標(biāo)識(shí)將要?jiǎng)h除不可見的列ifadw.Describe("#"+String(j)+".visible")="0"thenIFinteger(j)<27then//當(dāng)列小于26時(shí),excel中用A-Z表示列號(hào)first_del=char(integer(J)+64)else//大于26,小于等于52列時(shí),AA-AZ,大于52列時(shí)可能性不大未做考慮first_del="A"+char(integer(J)+38)endifcol_del=col_del+first_del+":"+first_del+","continueendif//當(dāng)列可見且為下拉數(shù)據(jù)窗口時(shí),數(shù)據(jù)值轉(zhuǎn)化為顯示值Ifadw.Describe("#"+String(j)+".edit.style")='dddw'Thenadw.GetChild(ls_colname[j],ldw_child)fori=1torowscount-1//"dm","dmyy"是我通常用下拉數(shù)據(jù)子窗口的值以及顯示值//更通用的方法是用DDDW.DataColumn,DDDW.DisplayColumn得到ll_found=ldw_child.Find("dm"+"='"+adw.getitemstring(i,j)+"'",1,ldw_child.RowCount())ifll_found>0thenSetRemote("R"+STRING(i+1)+"C"+STRING(J),ldw_child.getitemstring(ll_found,"dmyy"),handle)endif//另外一種方法,數(shù)據(jù)量大時(shí)比現(xiàn)用方法速度慢//SetRemote("R"+STRING(i+1)+"C"+STRING(J),adw.Describe("Evaluate('LookUpDisplay(#"+string(j)+")',"+string(i)+")"),handle)nextendifnextCloseChannel(handle)ifcol_del<>''thenCOL_DEL=LEFT(COL_DEL,LEN(COL_DEL)-2)//刪除不可見列ole_object.activesheet.range(col_del).DeleteendifSetPointer(oldpointer)ole_object.ActiveWorkBook.Save()ole_object.application.quit()ole_object.Disconnectobject()Destroyole_objectReturn1endfunctionstringls_assize,namedintli_value,li_rt,li_rc,li_rt1//livalue=gf_dwsavetoexcel(dw_detail)//ifdw_detail.rowcount()<1thenreturnSetPointer(HourGlass!)livalue=getfilesavename("SaveFile",ls_assize,named,"excel","excelfiles(*.xls),*.xls,"+&"Allfiles(*.*),*.*")IFli_value<>1thenreturnli_rt=dw_detail.saveas(ls_assize,excel!,false)SetPointer(Arrow!)SetPointer(HourGlass!)OLEObjectOle_1Ole_1=CreateOLEObjectli_rc=Ole_1.ConnectToObject(ls_assize)ifli_rc<>0thendestroyole_1returnendifOle_1.Application.Windows(named).Visible=TrueOle_1.Application.DisplayAlerts=Falseifli_rt=1then//aOle.Application.Workbooks[1].worksheets[1].columns(7).InsertSetPointer(HourGlass!)Ole_1.Application.Workbooks[1].worksheets[1].Rows(1).Insert//如何設(shè)置導(dǎo)出列的寬度,讓列之間有一定的空間?Ole_1.Sheets(1).Columns("A:Z").ColumnWidth=22.00//設(shè)置某個(gè)區(qū)間的列寬Ole_1.Sheets(1).Columns[1].ColumnWidth=13.00//設(shè)置某一列的列寬//aOle.Sheets(1).Columns("AG:AI").ColumnWidth=13.00//設(shè)置對(duì)齊方式//aOle.Sheets(1).Columns(1).Select//sheet1的第一列的對(duì)齊方式//aOle.Selection.HorizontalAlignment=-4131//居左//aOle.Sheets(1).Columns("A:Z").HorizontalAlignment=-4152//居右//aOle.Sheets(1).Selection.HorizontalAlignment=-4152//居右//aOle.Selection.HorizontalAlignment=-4108//居中Ole_1.Application.Workbooks[1].worksheets[1].Cells[1,1].value="ICAJCD"Ole_1.Application.Workbooks[1].worksheets[1].Cells[1,1].Font.FontStyle="bold"Ole_1.Application.Workbooks[1].worksheets[1].Cells[1,2].value="ICVICH"Ole_1.Application.Workbooks[1].worksheets[1].Cells[1,2].Font.FontStyle="bold"Ole_1.Application.Workbooks[1].worksheets[1].Cells[1,3].value="ICVJCH"Ol

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論