OLE操作EXCEL

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.

阅读更多
个人分类:
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭