Örnek Excel Şablonu

Excelden yükleme yapılacak programlar için örnek excel şablonu oluşturma.



TYPE-POOLSslistruxs.
TABLES: msscrfields.


*---excel
DATAgo_excel TYPE ole2_object" Excel object
      go_mapl  TYPE ole2_object,        " list of workbooks
      go_map   TYPE ole2_object,        " workbook
      go_zl    TYPE ole2_object,        " cell
      go_f     TYPE ole2_object.        " font


SELECTION-SCREEN 
BEGIN OF BLOCK bl1 WITH FRAME TITLE text-001.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON 2(25text-001 USER-COMMAND cmd1.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK bl1.

AT SELECTION-SCREEN.
   IF sscrfields-ucomm `CMD1`.
     PERFORM ornek_excel.
   ENDIF.



*&---------------------------------------------------------------------*
*&      Form  ORNEK_EXCEL
*&---------------------------------------------------------------------*
FORM ornek_excel .
  DATAlv_idx  LIKE sy-tabix.
  DATAlt_fcat TYPE lvc_t_fcat,
        ls_wa_fcat LIKE LINE OF lt_fcat.

* start Excel
  CREATE OBJECT go_excel `EXCEL.APPLICATION`.
 
  SET PROPERTY OF go_excel  `Visible` 1.

* get list of workbooks, initially empty
  CALL METHOD OF go_excel
      `Workbooks` go_mapl.
* add a new workbook
  CALL METHOD OF
    go_mapl
      `Add` go_map.

  PERFORM get_fcat TABLES lt_fcat .
  CHECK lineslt_fcat 1.
  DELETE lt_fcat WHERE fieldname `COLOR` OR
                       fieldname `LIGHTS`  .

  LOOP AT  lt_fcat INTO ls_wa_fcat.  "#EC CI_LOOP_INTO_WA
    lv_idx sy-tabix.
* output column headings to active excel sheet
    PERFORM fill_cell USING lv_idx ls_wa_fcat-scrtext_l.
    PERFORM fill_cell USING lv_idx ls_wa_fcat-fieldname.
  ENDLOOP.
  FREE OBJECT go_excel.
ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  GET_FCAT
*&---------------------------------------------------------------------*
FORM get_fcat TABLES pt_fcat STRUCTURE lvc_s_fcat .
  DATAlt_fcat   TYPE lvc_t_fcat,
        lv_struct TYPE tabname.

  IF p_ua `X` or p_uac `X`.
    lv_struct gc_struct1.
  ELSEIF p_ip `X`"or p_ipc = `X`.
    lv_struct gc_struct2.
  ELSEIF p_ipc `X`.
    lv_struct gc_struct4.
  ELSEIF p_knt `X`.
    lv_struct gc_struct3.
  ENDIF.

  CALL FUNCTION `LVC_FIELDCATALOG_MERGE`
    EXPORTING
      i_structure_name       lv_struct
    CHANGING
      ct_fieldcat            lt_fcat
    EXCEPTIONS
      inconsistent_interface 1
      program_error          2
      OTHERS                 3.
  IF sy-subrc EQ 0.
    pt_fcat[] lt_fcat[].
  ENDIF.
    LOOP AT pt_fcat REFERENCE INTO DATA(ls_lrd_fcat).
      CASE ls_lrd_fcat->fieldname.
        WHEN `ITEM_TEXT1`.
          ls_lrd_fcat->fieldname `COMP_TEXT` .
          ls_lrd_fcat->scrtext_l `MAKTX` .
      ENDCASE.
    ENDLOOP.
ENDFORM" GET_FCAT


*&---------------------------------------------------------------------*
*&      Form  FILL_CELL
*&---------------------------------------------------------------------*
FORM fill_cell USING j bold val.

  CALL METHOD OF
       go_excel
       `Cells`  go_zl
     EXPORTING
       #1       i
       #2       j.
  SET PROPERTY OF go_zl `Value` val .
  GET PROPERTY OF go_zl `Font` go_f.
  SET PROPERTY OF go_f  `Bold` bold .

ENDFORM" FILL_CELL