把数据一条一条写入excel解决方法


把数据一条一条写入excel
想把数据一条一条写入excel
constant integer ppLayoutBlank = 12 

OLEObject oleobject 

ole
object = CREATE OLEObject 


integer liret 


li
ret = oleobject.ConnectToObject("d:\test.xls ", "Excel.Application ") 

IF li
ret <> 0 THEN 

//如果Excel还没有打开,则新建。 

liret = oleobject.ConnectToNewObject( "Excel.Application ")

if liret <> 0 then 

MessageBox( 'OLE错误 ', 'OLE无法连接!错误号: ' + string(li
ret)) 

return  

end if 


这里就出现了问题,li_ret = -2
我用的是pb10.5 ,求大虾帮忙解决.

PowerBuilder语言基础 PowerBuilder 程序开发

撸腿毛 11 years, 9 months ago


在这个程序吧,可以正常执行的。
String lsFileName,lsorifile
oleobject ole1
int li
i,lirowcount,licurrow,liretvalue,lizt
dec ldcje
if dw
1.rowcount() > 0 then
if not directoryexists('d:\资产报表') then
if createdirectory('d:\资产报表') <> 1 then
messagebox('提示信息','生成d:\资产报表目录失败,请手工创建!')
return
end if
end if
lsfilename = 'd:\资产报表\固定资产库存清单' + string(today(),'yymmdd') + '.xls'
ls
orifile = esheererp.ofgetapppath() + '\excel templet\固定资产库存清单.xls'
if fileexists(ls
FileName) Then
if messagebox('提示信息',lsFileName+'文件已经存在,要覆盖吗?',Question!,YesNo!,1) = 2 then Return
End If
if fileexists(ls
orifile) then
if FileCopy(lsorifile,lsFileName,true) = 1 Then
Else
messagebox('提示信息','生成'+lsFileName+'文件失败!')
End If
else
messagebox('提示信息','找不到'+ls
orifile +'模板文件,不能另存为excel!')
return
end if
lirowcount = dw1.rowcount()
ole1 = create oleobject
li
Retvalue = ole1.Connecttonewobject("Excel.Application")
if li
RetValue <> 0 then
MessageBox('提示信息','不能联接到EXCEL,请确认你的机器上已经安装Excel!')
Return
end if
ole1.Visible = False
ole
1.workbooks.open(lsFileName)
ole
1.Application.Cells(1,1).value = dw1.object.ttitle.text//设置标题
ole1.Application.Cells(2,1).value = dw1.object.t1.text//设置统计条件
ole
1.Application.Cells(2,7).value = dw1.getitemstring(1,'computedate')//设置日期
ole1.Application.Cells(7,7).value = dw1.object.tuser.text//设置制表人
ole
1.Application.Cells(6,4).value = dw1.getitemdecimal(1,"compute4")
ole1.Application.Cells(6,6).value = dw1.getitemdecimal(1,"compute5")
ole
1.Application.Cells(6,8).value = dw1.getitemdecimal(1,"compute6")
if lirowcount > 2 then
for li
i = 1 to lirowcount - 2
ole
1.Application.Rows( "5:5").Select
ole1.Selection.Insert()
next
end if
li
currow = 3
werpmainc.ofSetBarMax(liRowCount)
for lii = 1 to lirowcount
werpmainc.ofStateBarStep()
li
currow ++
ole1.Application.Cells(licurrow,1).value = dw1.object.daima[lii]
ole1.Application.Cells(licurrow,2).value = dw1.object.wupinmingcheng[lii]
ole1.Application.Cells(licurrow,3).value = dw1.object.jiliangdangwei[lii]
ole1.Application.Cells(licurrow,4).value = dw1.object.shuliang[lii]
ole1.Application.Cells(licurrow,5).value = dw1.object.kucunjine[lii]
ole1.Application.Cells(licurrow,6).value = dw1.object.lingyongshulian[lii]
ole1.Application.Cells(licurrow,7).value = dw1.object.lingyongjine[lii]
ole1.Application.Cells(licurrow,8).value = dwpute1[li_i]

白色的羁绊 answered 11 years ago


打开控制面板的服务管理器,某些service停止了就会那样,把可疑的服务先都启动。


nacui7 answered 11 years ago


connecttonewobject('Word.application')
sheet.open(initial_filename)

 大致思路是这样,你该成excel的就成了


狂热@萌物 answered 11 years ago

Your Answer