关闭

OLE操作EXCEL

329人阅读 评论(0) 收藏 举报

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.

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:425419次
    • 积分:4410
    • 等级:
    • 排名:第7041名
    • 原创:86篇
    • 转载:41篇
    • 译文:0篇
    • 评论:11条
    文章分类
    最新评论