频道直达 - 专题 - 新闻 - 技巧 - 组网 - 开发 - 安全 - web编程 - 图像 - 操作系统 - 数据库 - 教育 - 旅游 - 健康 - 时尚 - 驱动 - 软件 - 游戏 - 多媒体 - ERP - 讨论组

如何通过OLE Automation拷贝数据窗口的数据到Excel

来源:互连网 作者: 出处:巧巧读书 2006-04-10 进入讨论组
QQRead:http://www.qqread.com/sybase/s132995205.html
  OLE automation in PowerBuilder 6.x, 7.x and 8.x has improved performance from the 5.x version. Data can be copied to Excel. This is a sample application that will copy all columns and rows to MS Excel.


Using OLE automation in PowerBuilder 6.x, 7.x and 8.x you can copy data from a datawindow to an Excel 8, Excel 97 or Excel 2000 spreadsheet much faster than with previous versions of PB. There is also a sample application available for download that will copy all columns and rows to a MS Excel spreadsheet.

The sample copies Datawindow Row 1 ,Column 1 to MS Excel Row 1 , Column 1 etc....

The script can be modified to copy only the desired columns/rows.

A template xls file could be opened and saved to a different xls filename, preserving the template.

Uncomment the Save or SaveAs lines accordingly.

The sample pbl provided uses the EAS DEMO DB's Employee table.
47867.zip is an sample PBL for techdoc 47867 "Copying Datawindow data to Microsoft Excel using OLE Automation"

The following script code is located in the "Copy DW Data to Excel using OLE Automation"
button , on the only window in the pbl. The example pbl is currently setup to open the file "c:\file1.xls"

Modify the path/filename or create file1.xls in the c:\ directory. The file can be an empty xls file.
 

long numcols , numrows , c, r
OLEObject xlapp , xlsub
int ret

// Set the # of columns and rows to process
// Currently Set to copy the entire DW

numcols = long(dw_1.Object.DataWindow.Column.Count)
numrows = dw_1.RowCount()

// Create the oleobject variable xlapp
xlApp = Create OLEObject

// Connect to Excel and check the return code
ret = xlApp.ConnectToNewObject( "Excel.Sheet" )
if ret < 0 then
MessageBox("Connect to Excel Failed !",string(ret))
return
end if

// Open a particular Excel file
xlApp.Application.Workbooks.Open("c:\file1.xls") //,false,true
// Make Excel visible
xlApp.Application.Visible = true

// Resolve the Excel reference once
// This technique shortens the script and improves performance
xlsub = xlapp.Application.ActiveWorkbook.Worksheets[1]

// Loop thru the Datawindow and Excel sheet
// The for/next loop copies all rows for each column
For c = 1 to numcols
For r = 1 to numrows
xlsub.cells[r,c] = dw_1.object.data[r,c]

Next
Next

// Save opened file
//xlApp.Application.Activeworkbook.Save()

// SaveAs a different filename
//xlApp.Application.Activeworkbook.SaveAs("c:\file2.xls")

// clean up
xlApp.DisConnectObject()
Destroy xlapp

进入讨论组讨论。
收藏此文】【 】【打印】【关闭
相关图文阅读
频道图文推荐
健 康 咨 询
时 尚 咨 询
巧巧读书宗旨
相关专题
讨论组问题推荐
站内各频道最新更新文档
站内最新制作专题
热门关键字导读
Photoshop教 程照片处理 照片制作 PS快捷键 抠图
计 算 机 故 障XP系统修复
艺 术 与 设 计设计 流媒体 设计欣赏 边框
计 算 机 安 全ARP
站内频道文章精选
巧巧电脑频道编辑信箱  告诉我们您想看的专题或文章