研究、分享我学习零售业SAP的历程
------------打造中国第一个零售SAP博客
REPORT YGL_MYOLE.
INCLUDE OLE2INCL.
* OLE OBJECT
DATA:
    MYEXCEL           TYPE OLE2_OBJECT,
    MYSHEET           TYPE OLE2_OBJECT,
    MYCELL             TYPE OLE2_OBJECT,
    MYWORKBOOK  TYPE OLE2_OBJECT.
.................................
*创建excel进程
CREATE OBJECT MYEXCEL 'EXCEL.APPLICATION'.
* 创建工作表
CALL METHOD OF MYEXCEL 'WORKBOOKS' = MYWORKBOOK.
* 创建sheet并添加到工作表
SET PROPERTY OF MYEXCEL 'SHEETSINNEWWORKBOOK' = 1.
CALL METHOD OF MYWORKBOOK 'ADD'.
* 选中excel中的cell,第一行的第二列。
CALL METHOD OF MYEXCEL 'CELLS' = MYCELL EXPORTING #1 = 1 #2 = 2.
* 设置被选中的cell的值
SET PROTERTY OF MYCELL 'VALUE' = 'HELLO WORD'. "你要输出的内容
GET PROPERTY OF MYEXCEL 'ACTIVESHEET' = MYSHEET.
GET PROPERTY OF MYEXCEL 'ACTIVEWORKBOOK' = MYWORKBOOK.
* 保存文件
CALL METHOD OF MYWORKBOOK 'SAVEAS' EXPORTING #1 = 'C:\TMP\AA.XLS' #2 = 1.
CALL METHOD OF MYWORKBOOK 'CLOSE'.
* 推出excel
CALL METHOD OF MYEXCEL 'QUIT'.
* 释放对象
FREE OBJECT MYSHEET.
FREE OBJECT MYWORKBOOK.
FREE OBJECT MYEXCEL.

转(http://www.itpub.net/redirect.php?tid=925318&goto=lastpost
posted on 2008-01-24 16:11  会东  阅读(2606)  评论(1编辑  收藏  举报