寫資料到本地EXCEL的模板中去

ZCLouis發表於2007-10-09

*&---------------------------------------------------------------------*
*& Report Z_TEST_2
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*

REPORT Z_TEST_2.
*---------------------------OLE----------------------------------*
include ole2incl.

data: excel type ole2_object, " Excel object
workbook type ole2_object, " Workbook object
sheet type ole2_object, " Worksheet object
range type ole2_object, " Range object
cell type ole2_object. " Cell object

data: sheet_name(20) value 'BS'. "Excel檔案裡的sheet name
data local_file like rcgfiletr-ftfront."下載檔案型別
local_file = 'c:DO_TEST_OLE.xls'.

START-OF-SELECTION.

data: c1 type i,
c2 type i,
c3 type i,
c4 type i.

create object excel 'EXCEL.APPLICATION'. " CREATE EXCEL OBJECT
if sy-subrc ne 0.
write: / 'Excel init failed, return code is ', sy-subrc.
exit.
endif.
set property of excel 'Visible' = 1.
call method of excel 'Workbooks' = workbook.
data h type i.

call method of workbook 'Open' exporting #1 = local_file.
call method of excel 'Sheets' = sheet exporting #1 = sheet_name.
call method of sheet 'SELECT' .

*填充抬頭
perform fill_range using 1 1 'F_TEST1'.
perform fill_range using 1 2 'F_TEST2'.

free object excel.
free object workbook.
free object sheet.
free object range.
free object cell.


*---------------------------------------------------------------------*
* FORM fill_range *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --&gt VALUE(F_ROW) *
* --&gt VALUE(F_COL) *
* --&gt VALUE(F_VALUE) *
*---------------------------------------------------------------------*
form fill_range using value(f_row)
value(f_col)
value(f_value).

call method of excel 'CELLS' = cell
exporting
#1 = f_row
#2 = f_col.
set property of cell 'VALUE' = f_value.
endform. "FILL_RANGE

[@more@]

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7941665/viewspace-975470/,如需轉載,請註明出處,否則將追究法律責任。

相關文章