200分 pb中把数据窗口的内容往word模板里面写,程序出了一点小错误,高手来看呀

yanudd 2004-08-05 10:57:06
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模板中写数据的资料也行呀!!!!!!!!!!!!




...全文
142 点赞 收藏 9
写回复
9 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
spencer0414 2004-08-21
恭喜恭喜!
回复
yanudd 2004-08-09
我知道了,也给大家分享一下!

ole_object.Selection.TypeBackspace() //相当于退格
dw_1.setredraw(true) //修改界面时不重绘
dw_1.setcolumn( ) //定位指定的列
dw_1.describe('#' + string(i) + ".name") 取第i 列的名称
回复
cxwsoftware 2004-08-06
帮你顶!
回复
yanudd 2004-08-06
ole_object.Selection.TypeBackspace()

dw_1.setredraw(true)

dw_1.setcolumn( )

dw_1.describe('#' + string(i) + ".name")

这些都是什么作用,帮忙解释一下好吗?
回复
DST_good 2004-08-05
f_cncharnum()中的代码
返回值类型:integer
参数:string astring

string ls_ch //临时单元
string ls_SecondSecTable //存放所有国标二级汉字读音
integer li_num = 0 //返回值
integer i,j

For i = 1 to Len(aString)
ls_ch = Mid(aString,i,1)
If Asc(ls_ch) >= 128 then //是汉字
li_num++
i = i+1
End if
Next

Return li_num
回复
DST_good 2004-08-05
constant integer ppLayoutBlank = 12
OLEObject ole_object
ole_object = CREATE OLEObject

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

ole_object.Visible = True

long ll_colnum,ll_rownum
constant long wdWord9TableBehavior = 1
constant long wdAutoFitFixed = 0
constant long wdCell = 12
string ls_value

//得到数据窗口数据的列数与行数(行数应该是数据行数 + 1)
ll_colnum = Long(dw_1.object.datawindow.column.count)
ll_rownum = dw_1.rowcount() + 1

ole_object.Documents.Add("E:\Documents and Settings\Administrator.CNE54.001\Application Data\Microsoft\Templates\Normal.dot",False,0)
ole_object.ActiveDocument.Tables.Add(ole_object.Selection.Range, ll_rownum, ll_colnum,wdWord9TableBehavior,wdAutoFitFixed)

string ls_colname
integer i,j,k
for i = 1 to ll_colnum
//得到标题头的名字
ls_colname = dw_1.describe('#' + string(i) + ".name") + "_t"
ls_value = dw_1.describe(ls_colname + ".text")
ole_object.Selection.TypeText(ls_value)
for k = 1 to f_cncharnum(ls_value)
ole_object.Selection.TypeBackspace()
next
ole_object.Selection.MoveRight(wdCell)
next

dw_1.setredraw(false)
ole_object.Selection.MoveLeft(wdCell)
for i = 2 to ll_rownum
for j = 1 to ll_colnum
dw_1.scrolltorow(i - 1)
dw_1.setcolumn(j)
ls_value = dw_1.gettext()
ole_object.Selection.MoveRight(wdCell)
ole_object.Selection.TypeText(ls_value)
for k = 1 to f_cncharnum(ls_value)
ole_object.Selection.TypeBackspace()
next
next
next
dw_1.setredraw(true)

constant long wdFormatDocument = 0
//保存新建的文档
ole_object.ActiveDocument.SaveAs("sample.doc", 0,False,"",True,"",False,False,False, False,False)

//断开OLE连接
Ole_Object.DisConnectObject()
Destroy Ole_Object
回复
yanudd 2004-08-05
谢谢毛毛大哥,我再仔细看看!
回复
yanudd 2004-08-05
不会吧,难道我们pb版没有高手了吗?
斑竹大哥来帮一下吧!!!!!!!!!!!!!!!!
!!!!!!!!!!!!!!!
回复
lzheng2001 2004-08-05
把那两行的代码贴出来,另外把错误信息贴出来
回复
相关推荐
发帖
数据库相关
创建于2007-09-28

738

社区成员

PowerBuilder 数据库相关
申请成为版主
帖子事件
创建了帖子
2004-08-05 10:57
社区公告
暂无公告