想把数据一条一条写入excel
constant integer ppLayoutBlank = 12
OLEObject ole_object
ole_object = CREATE OLEObject
integer li_ret
li_ret = ole_object.ConnectToObject("d:\test.xls ", "Excel.Application ")
IF li_ret <> 0 THEN
//如果Excel还没有打开,则新建。
li_ret = ole_object.ConnectToNewObject( "Excel.Application ")
if li_ret <> 0 then
MessageBox( 'OLE错误 ', 'OLE无法连接!错误号: ' + string(li_ret))
return
end if
这里就出现了问题,li_ret = -2
我用的是pb10.5 ,求大虾帮忙解决.
------解决方案--------------------
connecttonewobject('Word.application')
sheet.open(initial_filename)
大致思路是这样,你该成excel的就成了
------解决方案--------------------
打开控制面板的服务管理器,某些service停止了就会那样,把可疑的服务先都启动。
------解决方案--------------------
在这个程序吧,可以正常执行的。
String ls_FileName,ls_orifile
oleobject ole_1
int li_i,li_rowcount,li_currow,li_retvalue,li_zt
dec ldc_je
if dw_1.rowcount() > 0 then
if not directoryexists('d:\资产报表') then
if createdirectory('d:\资产报表') <> 1 then
messagebox('提示信息','生成d:\资产报表目录失败,请手工创建!')
return
end if
end if
ls_filename = 'd:\资产报表\固定资产库存清单' + string(today(),'yymmdd') + '.xls'
ls_orifile = esheererp.of_getapppath() + '\excel templet\固定资产库存清单.xls'
if fileexists(ls_FileName) Then
if messagebox('提示信息',ls_FileName+'文件已经存在,要覆盖吗?',Question!,YesNo!,1) = 2 then Return
End If
if fileexists(ls_orifile) then
if FileCopy(ls_orifile,ls_FileName,true) = 1 Then
Else
messagebox('提示信息','生成'+ls_FileName+'文件失败!')
End If
else
messagebox('提示信息','找不到'+ls_orifile +'模板文件,不能另存为excel!')
return
end if
li_rowcount = dw_1.rowcount()
ole_1 = create oleobject
li_Retvalue = ole_1.Connecttonewobject("Excel.Application")
if li_RetValue <> 0 then
MessageBox('提示信息','不能联接到EXCEL,请确认你的机器上已经安装Excel!')
Return
end if
ole_1.Visible = False
ole_1.workbooks.open(ls_FileName)
ole_1.Application.Cells(1,1).value = dw_1.object.t_title.text//设置标题
ole_1.Application.Cells(2,1).value = dw_1.object.t_1.text//设置统计条件
ole_1.Application.Cells(2,7).value = dw_1.getitemstring(1,'compute_date')//设置日期
ole_1.Application.Cells(7,7).value = dw_1.object.t_user.text//设置制表人
ole_1.Application.Cells(6,4).value = dw_1.getitemdecimal(1,"compute_4")
ole_1.Application.Cells(6,6).value = dw_1.getitemdecimal(1,"compute_5")
ole_1.Application.Cells(6,8).value = dw_1.getitemdecimal(1,"compute_6")
if li_rowcount > 2 then
for li_i = 1 to li_rowcount - 2
ole_1.Application.Rows( "5:5").Select
ole_1.Selection.Insert()
next
end if
li_currow = 3
w_erpmain_c.of_SetBarMax(li_RowCount)
for li_i = 1 to li_rowcount
w_erpmain_c.of_StateBarStep()
li_currow ++
ole_1.Application.Cells(li_currow,1).value = dw_1.object.daima[li_i]
ole_1.Application.Cells(li_currow,2).value = dw_1.object.wupinmingcheng[li_i]
ole_1.Application.Cells(li_currow,3).value = dw_1.object.jiliangdangwei[li_i]
ole_1.Application.Cells(li_currow,4).value = dw_1.object.shuliang[li_i]
ole_1.Application.Cells(li_currow,5).value = dw_1.object.kucunjine[li_i]
ole_1.Application.Cells(li_currow,6).value = dw_1.object.lingyongshulian[li_i]
ole_1.Application.Cells(li_currow,7).value = dw_1.object.lingyongjine[li_i]
ole_1.Application.Cells(li_currow,8).value = dw_1.object.compute_1[li_i]