首页 > 数据库 > 数据库开发技术 > 写数据到本地EXCEL的模板中去
*&---------------------------------------------------------------------*
*& 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 *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
* --> VALUE(F_ROW) *
* --> VALUE(F_COL) *
* --> 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
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/7941665/viewspace-975470/ ,如需转载,请注明出处,否则将追究法律责任。