*&---------------------------------------------------------------------*
*& Report ZDEMO15
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT zdemo15.
DATA:BEGIN OF gs_itab,
matnr TYPE makt-matnr,
maktx TYPE makt-maktx,
END OF gs_itab,
gt_itab LIKE TABLE OF gs_itab.
DATA:gv_lines TYPE i.
INCLUDE ole2incl.
DATA: gv_excel TYPE ole2_object, " Excel object
gv_mapl TYPE ole2_object, " list of workbooks
gv_map TYPE ole2_object, " workbook
gv_zl TYPE ole2_object, " cell
gv_f TYPE ole2_object. " font
* start Excel
CREATE OBJECT gv_excel 'EXCEL.APPLICATION'.
PERFORM err_hdl.
SET PROPERTY OF gv_excel 'Visible' = 1.
PERFORM err_hdl.
* get list of workbooks, initially empty
CALL METHOD OF
gv_excel
'Workbooks' = gv_mapl.
PERFORM err_hdl.
* add a new workbook
CALL METHOD OF
gv_mapl
'Add' = gv_map.
PERFORM err_hdl.
* output column headings to active Excel sheet
PERFORM fill_cell USING 1 1 1 '物料编码'.
PERFORM fill_cell USING 1 2 1 '物料描述'.
SELECT matnr maktx INTO TABLE gt_itab
FROM makt UP TO 10 ROWS.
gv_lines = 1.
LOOP AT gt_itab INTO gs_itab.
gv_lines = gv_lines + 1.
PERFORM fill_cell USING gv_lines 1 0 gs_itab-matnr.
PERFORM fill_cell USING gv_lines 2 0 gs_itab-maktx.
ENDLOOP.
* disconnect from Excel
FREE OBJECT gv_excel.
PERFORM err_hdl.
*&---------------------------------------------------------------------*
*& Form fill_cell
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->I text
* -->J text
* -->BOLD text
* -->VAL text
*----------------------------------------------------------------------*
FORM fill_cell USING i j bold val.
CALL METHOD OF
gv_excel
'Cells' = gv_zl
EXPORTING
#1 = i
#2 = j.
PERFORM err_hdl.
SET PROPERTY OF gv_zl 'Value' = val .
PERFORM err_hdl.
GET PROPERTY OF gv_zl 'Font' = gv_f.
PERFORM err_hdl.
SET PROPERTY OF gv_f 'Bold' = bold .
PERFORM err_hdl.
ENDFORM. "fill_cell
* output column headings to active Excel sheet
*&---------------------------------------------------------------------*
*& Form err_hdl
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
FORM err_hdl.
IF sy-subrc <> 0.
WRITE: / 'Fehler bei OLE-Automation:'(010), sy-subrc.
STOP.
ENDIF.
ENDFORM. " ERR_HDL
阅读(1674) | 评论(0) | 转发(0) |