PB 数据窗口数据导出到word文件中
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
PB 数据窗口数据导出到word,excel
博客分类:
powerbuilder
PB 数据窗口数据导出到word,excel, excel 可以自定义修改excel文档的列宽对齐方式,字体样式等
// dwsave2word 调用ole
global type gf_exportdata2word from function_object
end type
forward prototypes
global subroutine gf_exportdata2word (datawindow ad_datawindow)
end prototypes
global subroutine gf_exportdata2word (datawindow ad_datawindow);string ls_filepath
ls_filepath=gf_getfilesavename()
OleObject OleObjectWord
OleObjectWord=Create OleObject
// 连接word
if OleObjectWord.ConnectToNewObject("Word.application") <> 0 then
Messagebox("提示","ole连接错误!")
return
end if
OleObjectWord.visible=false //word文档在操作数据过程中是否可见
Long col_colnum,col_rownum
Constant Long wdTableBehavior=1
Constant Long wdAutoFitFixed=0
Constant Long wdCell=12
String str_value
// 得到数据窗口数据的列数和行数(行数应该是数据行数+1)
col_colnum=Long(ad_datawindow.object.datawindow.column.count)
col_rownum=ad_datawindow.rowcount() + 1
// 先在word文档中画好表格
SetPointer(HourGlass!)
OleObjectWord.Documents.Add
OleObjectWord.ActiveDocument.Tables.Add(OleObjectWord.Selection.Range,&
+col_rownum,col_colnum,wdTableBehavior,wdAutoFitFixed)
string ls_colname
integer i,j,k,l
for i=1 to col_colnum
//得到标题头的名称
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)
Next
ad_datawindow.setRedraw(false)
OleObjectWord.Selection.MoveLeft(wdCell)
SetPointer(HourGlass!)
for i=2 to col_rownum
for j=1 to col_colnum
ad_datawindow.Scrolltorow(i - 1)
ad_datawindow.SetColumn(j)
strvalue=ad_datawindow.GetItemstring(i - 1,j)
if isnull(str_value) then
strvalue=''
end if
OleObjectWord.Selection.MoveRight(wdCell)
OleObjectWord.Selection.TypeText(str_value)
next
next
ad_datawindow.setredraw(true)
Constant long wdFormatDocument=0
// 保存新建的文档
OleObjectWord.ActiveDocument.SaveAs(ls_filepath,0,false,"",true,"",false,false,false,fals e,false)
boolean lb_exist
lb_exist = FileExists(ls_filepath)
if lb_exist then
messagebox("提示","数据已经保存到"+ls_filepath)
end if
//断开ole连接
OleObjectWord.DisconnectObject()
destroy OleObjectWord
end subroutine
// dwsave2xls 调用ole
global type gf_dwsavetoexcel from function_object
end type
forward prototypes
global function integer gf_dwsavetoexcel (datawindow adw)
end prototypes
global function integer gf_dwsavetoexcel (datawindow adw); string xlsname, named integer value
string col_del,first_del
value = GetFileSaveName("另存为", xlsname,named,"XLS","Xls Files
(*.XLS), *.XLS")
if value = 1 then
adw.saveas(xlsname,Excel!,TRUE)
else
return 2
end if
constant integer ppLayoutBlank = 12
OLEObject ole_object
ole_object = CREATE OLEObject
integer li_ret