以文本方式查看主题

-  蓝色快车PB俱乐部论坛  (http://pb.besoft.com.cnhttp://pb.besoft.com.cn/bbs/index.aspindex.asp)
--  PowerBuilder MIS编程  (http://pb.besoft.com.cnhttp://pb.besoft.com.cn/bbs/index.aspbbs.asp?boardid=1)
----  数据窗口导出到excel时的一个问题  (http://pb.besoft.com.cnhttp://pb.besoft.com.cn/bbs/index.aspdispbbs.asp?boardid=1&rootid=4664&id=4756)


--  作者:guzyun
--  发布时间:2007/5/27 3:40:35

--  数据窗口导出到excel时的一个问题
从数据窗口导出到excel文档,导出的代码如下,但是导出来的文档中的数据比数据窗口中显示的数据少了第一行

其中,数据窗口对应一个表中全部数据,改表字段为 : 商品编号,商品名称,产地,供应商全称,进价,数量,金额

OLEObject ole_object,ole_workbooks
ole_object = create OLEObject

if ole_object.connecttonewobject("excel.application")<>0 then
    messagebox("提示","OLE连接失败!")
    return
end if
ole_object.workbooks.add
ole_object.visible = true

ole_workbooks = ole_object.worksheets(1)
ole_workbooks.cells(1,1).value = "商品编号"
ole_workbooks.cells(1,2).value = "商品名称"
ole_workbooks.cells(1,3).value = "产地"
ole_workbooks.cells(1,4).value = "供应商全称"
ole_workbooks.cells(1,5).value = "进价"
ole_workbooks.cells(1,6).value = "数量"
ole_workbooks.cells(1,7).value = "金额"
long row_num
for row_num = 2 to dw_1.rowcount() 
    ole_workbooks.cells(row_num,1).value = dw_1.getitemstring(row_num,1)
    ole_workbooks.cells(row_num,2).value = dw_1.getitemstring(row_num,2)
    ole_workbooks.cells(row_num,3).value = dw_1.getitemstring(row_num,3)
    ole_workbooks.cells(row_num,4).value = dw_1.getitemstring(row_num,4)
    ole_workbooks.cells(row_num,5).value = dw_1.getitemnumber(row_num,5)
    ole_workbooks.cells(row_num,6).value = dw_1.getitemnumber(row_num,6)
    ole_workbooks.cells(row_num,7).value = dw_1.getitemnumber(row_num,7)
next
ole_workbooks.saveas("d:\data.xls")
ole_object.quit()
ole_object.disconnectobject()
destroy ole_object
destroy ole_workbooks

出现这个问题,实在是迷茫,请哪位高手知道一下啊,在此谢过!


--  作者:2107
--  发布时间:2007/6/11 19:18:27

--  
不会吧??一定是哪里搞错了
--  作者:seabird
--  发布时间:2007/6/13 14:59:34

--  

for row_num = 2 to dw_1.rowcount() 
    ole_workbooks.cells(row_num,1).value = dw_1.getitemstring(row_num,1)
    ole_workbooks.cells(row_num,2).value = dw_1.getitemstring(row_num,2)
    ole_workbooks.cells(row_num,3).value = dw_1.getitemstring(row_num,3)
    ole_workbooks.cells(row_num,4).value = dw_1.getitemstring(row_num,4)
    ole_workbooks.cells(row_num,5).value = dw_1.getitemnumber(row_num,5)
    ole_workbooks.cells(row_num,6).value = dw_1.getitemnumber(row_num,6)
    ole_workbooks.cells(row_num,7).value = dw_1.getitemnumber(row_num,7)
next
改成如下:
for row_num = 1 to dw_1.rowcount() 
    ole_workbooks.cells(row_num+1,1).value = dw_1.getitemstring(row_num,1)
    ole_workbooks.cells(row_num+1,2).value = dw_1.getitemstring(row_num,2)
    ole_workbooks.cells(row_num+1,3).value = dw_1.getitemstring(row_num,3)
    ole_workbooks.cells(row_num+1,4).value = dw_1.getitemstring(row_num,4)
    ole_workbooks.cells(row_num+1,5).value = dw_1.getitemnumber(row_num,5)
    ole_workbooks.cells(row_num+1,6).value = dw_1.getitemnumber(row_num,6)
    ole_workbooks.cells(row_num+1,7).value = dw_1.getitemnumber(row_num,7)
next

--  作者:2107
--  发布时间:2007/6/14 18:28:40

--  

--  作者:ugly927846
--  发布时间:2007/7/2 15:25:58

--  
....................
--  作者:zhangrunping
--  发布时间:2007/7/7 15:25:18

--  
这种导出方法,数据窗口的格式出不去吧?!

">