使用XML的方式导出EXCEL

事务码STRANS。

1 、创建EXCEL文档模板,另存为 XML文档格式

打开文档将代码复制进STRANS的<tt:template> <tt:template>中间

部分定义

 

 2
在ECC中撸代码

REPORT ZWP_TEST.

TYPES: BEGIN OF TY_DATA,
         FIELD1 TYPE STRING,
         FIELD2 TYPE STRING ,
         FIELD3 TYPE STRING ,
         FIELD4 TYPE STRING ,
         FIELD5 TYPE STRING ,

       END   OF TY_DATA.

DATA: ITAB   TYPE STANDARD TABLE OF TY_DATA,
      LA_TAB LIKE LINE OF ITAB,
      XMLSTR TYPE STRING.

DATA: XML_TABLE TYPE STANDARD TABLE OF STRING.


DATA: WINDOW_TITLE      TYPE STRING,
      FULLPATH          TYPE STRING,
      PATH              TYPE STRING,
      USER_ACTION       TYPE I,
      DEFAULT_EXTENSION TYPE STRING,
      DEFAULT_FILE_NAME TYPE STRING,
      FILE_FILTER       TYPE  STRING,
      FILENAME          TYPE STRING,
      INITIALPATH       TYPE STRING.


START-OF-SELECTION.

  LA_TAB-FIELD1 = '中单'.
  LA_TAB-FIELD2 = ''.
  LA_TAB-FIELD3 = '不是'.
  LA_TAB-FIELD4 = ''.
  LA_TAB-FIELD5 = ''.
  APPEND LA_TAB TO ITAB.

  LA_TAB-FIELD1 = '打野'.
  LA_TAB-FIELD2 = '制霸'.
  LA_TAB-FIELD3 = '牛逼'.
  LA_TAB-FIELD4 = '卧槽'.
  LA_TAB-FIELD5 = '辅助大哥是大神'.
  APPEND LA_TAB TO ITAB.

  LA_TAB-FIELD1 = '打野'.
  LA_TAB-FIELD2 = '制霸'.
  LA_TAB-FIELD3 = '牛逼'.
  LA_TAB-FIELD4 = '卧槽'.
  LA_TAB-FIELD5 = '辅助大哥是大神'.
  APPEND LA_TAB TO ITAB.



  CALL  TRANSFORMATION ZTEST_STRANS
    SOURCE table = ITAB
    RESULT XML XMLSTR.

  REPLACE FIRST OCCURRENCE OF 'encoding="utf-16"' IN XMLSTR WITH 'encoding="gbk"'."显示中文
  APPEND XMLSTR TO XML_TABLE.


  MOVE '.XLS' TO DEFAULT_EXTENSION.
  MOVE 'XLS files (.XLS)|.XLS' TO FILE_FILTER.


  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG
    EXPORTING
      DEFAULT_EXTENSION = DEFAULT_EXTENSION
      DEFAULT_FILE_NAME = DEFAULT_FILE_NAME
      FILE_FILTER       = FILE_FILTER
      INITIAL_DIRECTORY = INITIALPATH
    CHANGING
      FILENAME          = FILENAME
      PATH              = PATH
      FULLPATH          = FULLPATH
      USER_ACTION       = USER_ACTION
    EXCEPTIONS
      CNTL_ERROR        = 1
      ERROR_NO_GUI      = 2
      OTHERS            = 3.

  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  CALL FUNCTION 'GUI_DOWNLOAD'
    EXPORTING
      FILENAME                = FULLPATH
      FILETYPE                = 'ASC'
    TABLES
      DATA_TAB                = XML_TABLE
    EXCEPTIONS
      FILE_WRITE_ERROR        = 1
      NO_BATCH                = 2
      GUI_REFUSE_FILETRANSFER = 3
      INVALID_TYPE            = 4
      OTHERS                  = 5.

  IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

以上是全过程,其余的后面再补充。20180726 1051.

 

 

 

posted @ 2018-07-26 10:53  追寻无限  阅读(2913)  评论(0编辑  收藏  举报