PB控制Word的老话题,新问题。

ChinaOk 2003-09-09 09:36:55
最近的工作需要用pb来控制word。所以研究了一些但收获不多。pb也是刚学一个星期,更是有些困难。

原来是用的pb里的ole控件来载入word,但发现程序此时对word的控制不灵活,

后改用直接生成ole对象的方法,createoleobject(“word.application”)

用这个方法基本商可以控制word的各项功能了。
比如控制菜单和工具栏的显示、隐藏就可以

ole_object.commandbars.item(“菜单名字”).Visible=true

但是如何才能获得word的一些事件呢?

比如OnQuit,,,OnOpen,,,OnNew等事件。。
我试着写
ole_object.Application.OnQuit=w_main.OnwdQuit
不好用。。。

有没有高人指点一二,,,谢谢了!!!

欢迎各位在此探讨 pb和 office系列的相关问题。。。

谢谢
...全文
372 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
rogery 2003-09-13
  • 打赏
  • 举报
回复
up
sinkiangscorpio 2003-09-12
  • 打赏
  • 举报
回复
string ls_value,ls_colname
dec sl
long k,i
int month1,month2
constant integer ppLayoutBlank = 12
string mystr
string myfilename
string mytitle
datastore lds_report
OLEObject ole_word
string str1
ole_word = CREATE OLEObject
lds_report = create datastore
lds_report.dataobject='d_gn_word_data'
lds_report.settransobject(sqlca)
lds_report.retrieve()

//连接PowerPoint
IF ole_word.ConnectToNewObject("Word.Application") <> 0 THEN
MessageBox('OLE错误','OLE无法连接!')
return
END IF

ole_word.Visible = True


constant long wdWord9TableBehavior = 1
constant long wdAutoFitFixed = 0
constant long wdCell = 12
constant long wdCelb = 6

month1=integer(right(as_date0,2))
month2=integer(right(as_date1,2))
ole_word.Documents.Add(gs_path+"\gnyy_report\report.dot",False,0)
//表头初始化

ls_value= gf_set_title(as_date0,as_date1)
mytitle=gs_path+"\gnyy_report\"+ls_value+"report.dot"
myfilename=ls_value+"report.dot"

ole_word.selection.goto(true,0,0,"k2")
ole_word.Selection.TypeText(ls_value)
for k = 1 to f_cncharnum(ls_value)
ole_word.Selection.TypeBackspace()
next

//月份初始化
if month1 = month2 then
ls_value=gf_chinese_number(month1)
else
ls_value=gf_chinese_number(month1)+"-"+gf_chinese_number(month2)
end if

for i=3 to 15
str1="k"+string(i)
ole_word.selection.goto(true,0,0,str1)
ole_word.Selection.TypeText(ls_value)
for k = 1 to f_cncharnum(ls_value)
ole_word.Selection.TypeBackspace()
next
next



for i=1 to 33
if i>=24 and i<=30 then continue
str1="a"+string(i)

ls_value=string(lds_report.object.b[i],'#####.00')

ole_word.selection.goto(true,0,0,str1)
ole_word.Selection.TypeText(ls_value)
for k = 1 to f_cncharnum(ls_value)
ole_word.Selection.TypeBackspace()
next
next


for i=1 to 33
if i>=24 and i<=30 then continue
str1="b"+string(i)
ls_value=string(lds_report.object.a[i],'#####.00')
ole_word.selection.goto(true,0,0,str1)
ole_word.Selection.TypeText(ls_value)
for k = 1 to f_cncharnum(ls_value)
ole_word.Selection.TypeBackspace()
next
next



for i=1 to 33
if i>=24 and i<=30 then continue
str1="c"+string(i)
ls_value=string(lds_report.object.i[i],'#####.00')
ole_word.selection.goto(true,0,0,str1)
ole_word.Selection.TypeText(ls_value)
for k = 1 to f_cncharnum(ls_value)
ole_word.Selection.TypeBackspace()
next
next


for i=1 to 33
if i>=24 and i<=30 then continue
str1="d"+string(i)
ls_value=string(lds_report.object.d[i],'#####.00')
ole_word.selection.goto(true,0,0,str1)
ole_word.Selection.TypeText(ls_value)
for k = 1 to f_cncharnum(ls_value)
ole_word.Selection.TypeBackspace()
next
next



for i=1 to 33
if i>=24 and i<=30 then continue
str1="e"+string(i)
ls_value=string(lds_report.object.f[i])
ole_word.selection.goto(true,0,0,str1)
ole_word.Selection.TypeText(ls_value)
for k = 1 to f_cncharnum(ls_value)
ole_word.Selection.TypeBackspace()
next
next


for i=24 to 30
str1="f"+string(i)
ls_value=string(lds_report.object.g[i])
ole_word.selection.goto(true,0,0,str1)
ole_word.Selection.TypeText(ls_value)
for k = 1 to f_cncharnum(ls_value)
ole_word.Selection.TypeBackspace()
next
next



for i=24 to 30
str1="g"+string(i)
ls_value=string(lds_report.object.h[i])
ole_word.selection.goto(true,0,0,str1)
ole_word.Selection.TypeText(ls_value)
for k = 1 to f_cncharnum(ls_value)
ole_word.Selection.TypeBackspace()
next
next


for i=24 to 30
str1="a"+string(i)
ls_value=string(lds_report.object.a[i],'####.00')
ole_word.selection.goto(true,0,0,str1)
ole_word.Selection.TypeText(ls_value)
for k = 1 to f_cncharnum(ls_value)
ole_word.Selection.TypeBackspace()
next
next









ole_word.ActiveDocument.SaveAs(mytitle, 0,False,"",True,"",False,False,False, False,False)
ole_word.ActiveDocument.Close()
ole_word.Application.Quit()
ole_word.DisConnectObject()
messagebox("顺利通过","本月月报已经自动生成到"+gs_path+"\gnyy_report\目录下,名称为"+myfilename)
Destroy ole_word

sinkiangscorpio 2003-09-12
  • 打赏
  • 举报
回复
to ldy(罗大佑) :
在word当中怎样才能合并第一列表格呢?我用宏才实现的。
第二列以及其他列都可以的。
怎么样用程序合并第一列表格呢?
dotnba 2003-09-12
  • 打赏
  • 举报
回复
long ll_rownum
string ls_dotname,ls_docname,ls_value
integer i,k,j,li_Row//,li_mod,li_div
//Word Ole对象
OLEObject ole_word

ll_rownum = dw_print.RowCount()
if ll_rownum = 0 then return false

ole_word = CREATE OLEObject
//连接word
IF ole_word.ConnectToNewObject("word.Application") <> 0 THEN
Destroy ole_word
MessageBox('OLE错误','OLE无法连接!')
return false
END IF
ls_dotname = gs_current_dir + "\template\label_" + string(ai_format) + ".dot"
if Not FileExists(ls_dotname) then
Destroy ole_word
MessageBox("提示","Word模板文件不存在。")
return false
End if
//ole_word.Visible = true
hpb_1.visible = true
hpb_1.Position = 0
hpb_1.SetRange(0,ll_rownum)

choose case ai_format
case 1
li_Row = 15
case 2
li_Row = 7
case 3
li_Row = 4
end choose
for i = 1 to ll_rownum
hpb_1.StepIt()
K++
if Mod(i,li_Row) = 1 then
//按照模板新建word文件
ole_word.Documents.Add(ls_dotname)
k = 1
End if
Try
ls_value = dw_print.getitemstring(i,'item237')
if isnull(ls_value) then ls_value='';
ole_word.selection.goto(true,0,0,'item237_' + string(k,"00"))
ole_word.selection.typetext(ls_value)
//档案分类号
ls_value = dw_print.getitemstring(i,'vol_dh')
if isnull(ls_value) then ls_value='';
ole_word.selection.goto(true,0,0,'vol_dh_' + string(k,"00"))
ole_word.selection.typetext(ls_value)
//文档主标题
ls_value = dw_print.getitemstring(i,'title')
if isnull(ls_value) then ls_value='';
ole_word.selection.goto(true,0,0,'title_' + string(k,"00"))
ole_word.selection.typetext(ls_value)
Catch (RuntimeError ErrMark)
MessageBox("提示","Word模板已经损坏。~r~n详细信息为:~r~n" + ErrMark.GetMessage() + &
"~r~n请与系统管理员联系。")
Exit
End Try
If K = li_Row Or i = ll_rownum then
//打印
Try
ole_word.application.ActiveDocument.printout()
ole_word.ActiveDocument.Close(False)
Catch (RuntimeError ErrPrint)
MessageBox("提示","找不到打印机。~r~n详细信息为:~r~n" + ErrPrint.GetMessage() + &
"~r~n请与系统管理员联系。")
Exit
end try
End if
Next

//断开连接,销毁对象
ole_word.Application.Quit(False)
ole_word.DisConnectObject()
Destroy ole_word
hpb_1.Visible = false
return true
runsoft 2003-09-09
  • 打赏
  • 举报
回复
使用OFFICE的宏跟中,你就可以得到相关的方法和属性。VBA
MaJia2004 2003-09-09
  • 打赏
  • 举报
回复
可能只能借助ole控件,不能直接使用OLEOBJECT对象
ChinaOk 2003-09-09
  • 打赏
  • 举报
回复
哪位有高招,指点一下。拜托~~
jdsnhan 2003-09-09
  • 打赏
  • 举报
回复
前两天有个帖子讨论了office问题,你找找看吧。
tiggerliu 2003-09-09
  • 打赏
  • 举报
回复
delphi可以,powerbuilder就不可以吗,一知半解
berry0919 2003-09-09
  • 打赏
  • 举报
回复
关注
ChinaOk 2003-09-09
  • 打赏
  • 举报
回复
我想知道怎么得到它的事件,比如关闭文档,保存文档。

delphi里就可以得到这些事件,

680

社区成员

发帖
与我相关
我的任务
社区描述
PowerBuilder API 调用
社区管理员
  • API 调用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧