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
阅读(2853) | 评论(0) | 转发(0) |