200分 pb中把数据窗口的内容往word模板里面写,程序出了一点小错误,高手来看呀
pb中把数据窗口的内容往word模板里面写,程序出了一点小错误,高手来看呀
我建了一个word模板,需要插入动态数据的地方插入了书签,
现在写了代码,把数据窗口(dw_1,dw_2)的内容往这个模板里面写,程序运行时出了一点小错误,36行出错了,我把36行注释掉后44行又出错了,希望高手指点一下,我把代码附在下面,另外,希望大家给点这方面的资料看看,谢谢了
onstant integer pplayoutblank =12
OLEo b j e c t ole_o b j e c t
ole_o b j e c t= create oleo b j e c t
integer li_ret
//建立与word的连接
li_ret=ole_o b j e c t.connecttoo b j e c t("word.application")
if li_ret <>0 then
//如果word没有打开,咱新建一个word文件
li_ret=ole_o b j e c t.connecttonewo b j e c t("word.application")
if li_ret <>0 then
messagebox("ole错误","ole无法连接,错误号:"+string(li_ret))
return
end if
ole_o b j e c t.visible=false
end if
string ls_modelfilename
ls_modelfilename=sle_1.text
string ls_savefilename
ls_savefilename=sle_2.text
ole_o b j e c t.documents.open(ls_modelfilename)
constant long wdword9tablebehavior = 1
constant long wdautofitfixed=0
constant long wdcell=12
long i,j,k,ll_colnum,ll_rownum
string ls_value,ls_colname
//输出清单表头
ll_colnum=long(dw_1.o b j e c t.datawindow.column.count)
dw_1.setredraw( false)
for i=1 to ll_colnum
dw_1.setcolumn( j)
ls_value=dw_1.gettext()
ls_colname=dw_1.describe('#'+string(j)+".name")
if ls_colname="name" then
ls_savefilename+="\作者"+ls_value+"的著作清单.doc"
end if
ole_o b j e c t.selection.goto(true,0,0,ls_colname) //36行
ole_o b j e c t.selection.typetext(ls_value)
for k=1 to f_getchinesenum(ls_value)
ole_o b j e c t.selection.typebackspace()
next
next
dw_1.setredraw(true)
//输出清单
ll_colnum=long(dw_2.o b j e c t.datawindow.colnum.count) //44行
ll_rownum=dw_2.rowcount( )+1
ole_o b j e c t.selection.goto(true,0,0,'list')
ole_o b j e c t.activedocument.tables.add(ole_o b j e c t.selection.range,ll_rownum,ll_colnum,wdword9tablebehavior,wdautofitfixed)
ole_o b j e c t.selection.moveleft(wdcell)
for i=1 to ll_colnum
//得到标题名字
ls_colname=dw_2.describe('#'+string(j)+".name") +"_t"
ls_value=dw_2.describe(ls_colname+".text")
ole_o b j e c t.selection.typetext(ls_value)
for k=1 to f_getchinesenum(ls_value)
ole_o b j e c t.selection.typebackspace()
next
ole_o b j e c t.selection.moveright(wdcell)
next
//输出清单数据
dw_2.setredraw(false)
ole_o b j e c t.selection.moveleft(wdcell)
for i=2 to ll_rownum
for j=1 to ll_colnum
dw_2.scrolltorow( i - 1)
dw_2.setcolumn( j)
ls_value=dw_2.gettext( )
ole_o b j e c t.selection.moveright(wdcell)
ole_o b j e c t.selection.typetext(ls_value)
for k=1 to f_getchinesenum(ls_value)
ole_o b j e c t.selection.typebackspace()
next
next
next
dw_2.setredraw( true)
constant long wdformatdocument=0
//保存作者详细清单
ole_o b j e c t.activedocument.saveas(ls_savefilename,1)
ole_o b j e c t.application.quit()
//断开ole连接
ole_o b j e c t.disconnecto b j e c t()
destroy ole_o b j e c t
messagebox("提示","作者详细著作清单word文档已经生成!")
希望大家提供点点资料来看!!!!!!!!!!!
pb往word模板中写数据的资料也行呀!!!!!!!!!!!!