pb,word,表格

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

竭诚为您提供优质文档/双击可除
pb,word,表格
篇一:pb数据窗口导出word、excel文档
dw2word,dw2xls
pb数据窗口数据导出到word,excel,excel可以自定义修改excel文档的列宽对齐方式,字体样式等
//dwsave2word调用ole
globaltypegf_exportdata2wordfromfunction_object endtype
forwardprototypes
globalsubroutinegf_exportdata2word(datawindowad_dat awindow)endprototypes
globalsubroutinegf_exportdata2word(datawindowad_dat awindow);stringls_filepath
ls_filepath=gf_getfilesavename()
oleobjectoleobjectword
oleobjectword=createoleobject
//连接word
ifoleobjectword.connecttonewobject("word.applicatio n")0thenmessagebox("提示","ole连接错误!") return
endif
oleobjectword.visible=false//word文档在操作数据过程中是否可见longcol_colnum,col_rownum
constantlongwdtablebehavior=1
constantlongwdautoFitFixed=0
constantlongwdcell=12
stringstr_value
//得到数据窗口数据的列数和行数(行数应该是数据行数+1)
col_colnum=long(ad_datawindow.object.datawindow.col umn.count)col_rownum=ad_datawindow.rowcount()+1 //先在word文档中画好表格
setpointer(hourglass!)
oleobjectword.documents.add
oleobjectword.activedocument.tables.add(oleobjectwo rd.selection.Range,#+string(i)+".name")+"_t"str_val ue=ad_datawindow.describe(ls_colname+".text") oleobjectword.selection.typetext(str_value)
oleobjectword.selection.moveRight(wdcell)
next
ad_datawindow.setRedraw(false)
oleobjectword.selection.moveleft(wdcell)
setpointer(hourglass!)
fori=2tocol_rownum
forj=1tocol_colnum
ad_datawindow.scrolltorow(i-1)
ad_datawindow.setcolumn(j)
str_value=ad_datawindow.getitemstring(i-1,j)
ifisnull(str_value)then
str_value=
endif
oleobjectword.selection.moveRight(wdcell)
oleobjectword.selection.typetext(str_value)
next
next
ad_datawindow.setredraw(true)
constantlongwdFormatdocument=0
//保存新建的文档
oleobjectword.activedocument.saveas(ls_filepath,0,f alse,"",true,"",false,false,false,false,false) booleanlb_exist
lb_exist=Fileexists(ls_filepath)
iflb_existthen
messagebox("提示","数据已经保存到"+ls_filepath) endif
//断开ole连接
oleobjectword.disconnectobject()
destroyoleobjectword
endsubroutine
//dwsave2xls调用ole
globaltypegf_dwsavetoexcelfromfunction_object
endtype
forwardprototypes
globalfunctionintegergf_dwsavetoexcel(datawindowadw) endprototypes
globalfunctionintegergf_dwsavetoexcel(datawindowadw );stringxlsname,named
integervalue
stringcol_del,first_del
value=getFilesavename("另存
",xlsname,named,"xls","xlsFiles(*.xls),*.xls")ifval ue=1then
adw.saveas(xlsname,excel!,tRue)
else
return2
endif
constantintegerpplayoutblank=12
oleobjectole_object
ole_object=cReateoleobject
integerli_ret
li_ret=ole_object.connecttoobject("","excel.applica tion")iFli_ret0then
li_ret=ole_object.connecttonewobject("excel.applica tion")iFli_ret0then
messagebox("ole错误","ole无法连接!~r~n错号:"+string(li_ret))
Return0
endiF
ole_object.visible=False
endiF
pointeroldpointer
oldpointer=setpointer(hourglass!)
ole_object.workbooks.open(xlsname)
ole_object.worksheets[1].activate
longcolumncount,rowscount
columncount=long(adw.object.datawindow.column.count )rowscount=adw.rowcount()+1
stringls_colname[],ls_value
integeri,j
longhandle为误
handle=openchannel("excel",xlsname)
//将列名转化为中文名称,即标题头名称
forj=1tocolumncount
ls_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)
next
datawindowchildldw_child
longll_found
Forj=1tocolumncount
//col_del标识将要删除不可见的列
ifadw.describe("#"+string(j)+".visible")="0"then iFinteger(j) //当列小于26时,excel中用a-z表示列号
first_del=char(integer(j)+64)
else
//大于26,小于等于52列时,aa-az,大于52列时可能性不大未做考虑first_del="a"+char(integer(j)+38) endif
col_del=col_del+first_del+":"+first_del+","
continue
endif
//当列可见且为下拉数据窗口时,数据值转化为显示值
ifadw.describe("#"+string(j)+".edit.style")=dddwthe n
adw.getchild(ls_colname[j],ldw_child)
fori=1torowscount-1
//"dm","dmyy"是我通常用下拉数据子窗口的值以及显示值//更通用的方法是用dddw.datacolumn,
dddw.displaycolumn得到
ll_found=ldw_child.Find("dm"+"="+adw.getitemstring( i,j)+"",1,ldw_child.Rowcount())
ifll_found>0then
setRemote("R"+stRing(i+1)+"c"+stRing(j),ldw_child.g etitemstring(ll_found,"dmyy"),handle)
endif
//另外一种方法,数据量大时比现用方法速度慢
//setRemote("R"+stRing(i+1)+"c"+stRing(j),adw.descr ibe("evaluate(lookupdisplay(#"+string(j)+"),"+strin
g(i)+")"),handle)
next
endif
next
closechannel(handle)
ifcol_delthen
col_del=leFt(col_del,len(col_del)-2)
//删除不可见列
ole_object.activesheet.range(col_del).delete endif
setpointer(oldpointer)
ole_object.activeworkbook.save()
ole_object.application.quit()
ole_object.disconnectobject()
destroyole_object
Return1
endfunction
stringls_assize,named
intli_value,li_rt,li_rc,li_rt1
//li_value=gf_dwsavetoexcel(dw_detail)
//ifdw_detail.rowcount()
setpointer(hourglass!)
li_value=getfilesavename("saveFile",ls_assize,named ,"excel","excelfiles(*.xls),*.xls,"+stringls_filepa thls_filepath=gf_getfilesavename()
oleobjectoleobjectword
oleobjectword=createoleobject
//连接word
ifoleobjectword.connecttonewobject("word.applicatio n")0then
messagebox("提示","ole连接错误!")
return
endif
oleobjectword.visible=false//word文档在操作数据过程中是否可见
longcol_colnum,col_rownum
constantlongwdtablebehavior=1
constantlongwdautoFitFixed=0
constantlongwdcell=12
stringstr_value
//得到数据窗口数据的列数和行数(行数应该是数据行数+1)
col_colnum=long(ad_datawindow.object.datawindow.col
umn.count)
col_rownum=ad_datawindow.rowcount()+1
//先在word文档中画好表格
setpointer(hourglass!)
oleobjectword.documents.add
oleobjectword.activedocument.tables.add(oleobjectwo
rd.selection.Range,#+string(i)+".name")+"_t"
strvalue=ad_datawindow.describe(ls_colname+".text") oleobjectword.selection.typetext(str_value)
oleobjectword.selection.moveRight(wdcell)
next
ad_datawindow.setRedraw(false)
oleobjectword.selection.moveleft(wdcell)
setpointer(hourglass!)
fori=2tocol_rownum
forj=1tocol_colnum
ad_datawindow.scrolltorow(i-1)
ad_datawindow.setcolumn(j)
1121。

相关文档
最新文档