REPORT ZEXCEL_ZLT.
TYPE-POOLS OLE2 .
****定义OLE对象****
DATA: APPLICATION TYPE OLE2_OBJECT, "定义EXCEL对象
WORKBOOK TYPE OLE2_OBJECT, "定义工作区对象
WORKSHEET TYPE OLE2_OBJECT. "定义具体的SHEET对象
DATA CELL TYPE OLE2_OBJECT. "定义CELL对象
****存储每个CELL值得变量****
DATA: VAL1(30) TYPE C.
****每个CELL的位置****
DATA: R1 TYPE I,
R2 TYPE I.
****创建EXCEL对象*****
CREATE OBJECT APPLICATION 'Excel.Application'.
****创建工作区对象*****
CALL METHOD OF APPLICATION 'Workbooks' = WORKBOOK.
*******************以下是新增一个SHEET操作********************
SET PROPERTY OF APPLICATION 'SheetsInNewWorkbook' = 1.
CALL METHOD OF WORKBOOK 'ADD' = WORKSHEET.
CALL METHOD OF WORKSHEET 'ACTIVATE'.
****向EXCEL中写入数据****
R1 = 1.
R2 = 2.
VAL1 = 'CON'.
CALL METHOD OF APPLICATION 'CELLS' = CELL
EXPORTING
#1 = R1
#2 = R2.
SET PROPERTY OF CELL 'VALUE' = VAL1.
****保存文件****
CALL METHOD OF worksheet 'SAVEAS'
EXPORTING #1 = 'C:/file.xls'
#2 = 1.
****关闭WORKSHEET****
CALL METHOD OF WORKSHEET 'CLOSE'.
****关闭WORKBOOK****
CALL METHOD OF WORKBOOK 'CLOSE'.
****关闭EXCEL对象****
CALL METHOD OF APPLICATION 'QUIT'.
****释放对象****
FREE OBJECT CELL.
FREE OBJECT WORKSHEET.
FREE OBJECT WORKBOOK.
FREE OBJECT APPLICATION.
TYPE-POOLS OLE2 .
****定义OLE对象****
DATA: APPLICATION TYPE OLE2_OBJECT, "定义EXCEL对象
WORKBOOK TYPE OLE2_OBJECT, "定义工作区对象
WORKSHEET TYPE OLE2_OBJECT. "定义具体的SHEET对象
DATA CELL TYPE OLE2_OBJECT. "定义CELL对象
****存储每个CELL值得变量****
DATA: VAL1(30) TYPE C.
****每个CELL的位置****
DATA: R1 TYPE I,
R2 TYPE I.
****创建EXCEL对象*****
CREATE OBJECT APPLICATION 'Excel.Application'.
****创建工作区对象*****
CALL METHOD OF APPLICATION 'Workbooks' = WORKBOOK.
*******************以下是新增一个SHEET操作********************
SET PROPERTY OF APPLICATION 'SheetsInNewWorkbook' = 1.
CALL METHOD OF WORKBOOK 'ADD' = WORKSHEET.
CALL METHOD OF WORKSHEET 'ACTIVATE'.
****向EXCEL中写入数据****
R1 = 1.
R2 = 2.
VAL1 = 'CON'.
CALL METHOD OF APPLICATION 'CELLS' = CELL
EXPORTING
#1 = R1
#2 = R2.
SET PROPERTY OF CELL 'VALUE' = VAL1.
****保存文件****
CALL METHOD OF worksheet 'SAVEAS'
EXPORTING #1 = 'C:/file.xls'
#2 = 1.
****关闭WORKSHEET****
CALL METHOD OF WORKSHEET 'CLOSE'.
****关闭WORKBOOK****
CALL METHOD OF WORKBOOK 'CLOSE'.
****关闭EXCEL对象****
CALL METHOD OF APPLICATION 'QUIT'.
****释放对象****
FREE OBJECT CELL.
FREE OBJECT WORKSHEET.
FREE OBJECT WORKBOOK.
FREE OBJECT APPLICATION.