用户名: 密码: 免费注册 忘记密码? 网站地图 | 加入收藏 | 设为首页
首页 | 新闻 | 工具 | 系统 | 办公 | 聊天 | 多媒体 | 网页 | 运营 | 平面 | 欣赏 | 数据库 | 程序 | 服务器 | 组网
网页 | 3dmax | Ghost | Windows Xp| Dreamweaver | photoshop | Flash | office | Alexa | Css | QQ | Asp | PHP | Jsp | Access
Flash MX 2004入门 | 网站推广策略 | CorelDRAW入门 | ASP学习 | 网站建设大师功 | Word入门
  iTbulo.com > 学院 > 数据库开发教程 > Sybase教程 > 产品技巧 > 文章正文
如何通过OLE Automation拷贝数据窗口的数据到Excel
iTbulo.COM 2005-9-3 佚名()
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. www.chinai tp ow er.comkijb4hK

The sample copies Datawindow Row 1 ,Column 1 to MS Excel Row 1 , Column 1 etc.... www.chinai tp ow er.comkijb4hK

The script can be modified to copy only the desired columns/rows. www.chinai tp ow er.comkijb4hK

A template xls file could be opened and saved to a different xls filename, preserving the template. www.chinai tp ow er.comkijb4hK

Uncomment the Save or SaveAs lines accordingly. www.chinai tp ow er.comkijb4hK

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" www.chinai tp ow er.comkijb4hK

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" www.chinai tp ow er.comkijb4hK

Modify the path/filename or create file1.xls in the c:\ directory. The file can be an empty xls file.
  www.chinai tp ow er.comkijb4hK

long numcols , numrows , c, r
OLEObject xlapp , xlsub
int ret www.chinai tp ow er.comkijb4hK

// Set the # of columns and rows to process
// Currently Set to copy the entire DW www.chinai tp ow er.comkijb4hK

numcols = long(dw_1.Object.DataWindow.Column.Count)
numrows = dw_1.RowCount() www.chinai tp ow er.comkijb4hK

// Create the oleobject variable xlapp
xlApp = Create OLEObject www.chinai tp ow er.comkijb4hK

// 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 www.chinai tp ow er.comkijb4hK

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

// Resolve the Excel reference once
// This technique shortens the script and improves performance
xlsub = xlapp.Application.ActiveWorkbook.Worksheets[1] www.chinai tp ow er.comkijb4hK

// 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] www.chinai tp ow er.comkijb4hK

Next
Next www.chinai tp ow er.comkijb4hK

// Save opened file
//xlApp.Application.Activeworkbook.Save() www.chinai tp ow er.comkijb4hK

// SaveAs a different filename
//xlApp.Application.Activeworkbook.SaveAs("c:\file2.xls") www.chinai tp ow er.comkijb4hK

// clean up
xlApp.DisConnectObject()
Destroy xlappwww.chinai tp ow er.comkijb4hK

文章搜索
相关资讯
相关文章 相关下载
新世代蠕虫病毒通过IM肆意传播
网站如何树自己品牌?
对个人网站如何制作才能成功的一点看法
如何写友情链接交换信
博客网站—如何搏取自己的商机?
焦点信息