zoukankan      html  css  js  c++  java
  • 进阶-案例九: WD中实现export 到Excel,Doc,Txt.

    1、导出excel 文件代码

    导出事件代码:

    METHOD onactionimport .
    *导出excel:  
      DATA: lo_node TYPE REF TO if_wd_context_node,
            lo_elem TYPE REF TO if_wd_context_element,
            ls_context TYPE wd_this->element_flight,
            lt_context TYPE wd_this->elements_flight,
            lw_string TYPE string,
            lw_xstring TYPE xstring.
    * get the table's context
      lo_node = wd_context->get_child_node( name = 'FLIGHT' ).
      lo_node->get_static_attributes_table( IMPORTING table = lt_context ).
    * create the String(Line)
      LOOP AT lt_context INTO ls_context.
        CONCATENATE lw_string ls_context-carrid
        ls_context-connid
    *    ls_context-text
        cl_abap_char_utilities=>newline INTO
        lw_string SEPARATED BY cl_abap_char_utilities=>horizontal_tab.
      ENDLOOP.
    * convert the string => Xstring
      CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
        EXPORTING
          text     = lw_string
    *     MIMETYPE = ' '
    *     ENCODING =
        IMPORTING
    
          buffer   = lw_xstring
        EXCEPTIONS
          failed   = 1
          OTHERS   = 2.
    * export the XString to Excel
      wdr_task=>client_window->client->attach_file_to_response(
    **path to the word file
    i_filename = 'WDP.xls'
    ** String Variable
      i_content = lw_xstring
    * File Type
    i_mime_type = 'EXCEL' ).
    ENDMETHOD.

     2、若是导出word的话改下参数

    * export the XString to Excel
      wdr_task=>client_window->client->attach_file_to_response(
    **path to the word file
    i_filename = 'WDP.doc'"
    ** String Variable
      i_content = lw_xstring
    * File Type
    i_mime_type = 'word').

    3、若是导出text的话改下参数

    * export the XString to Excel
      wdr_task=>client_window->client->attach_file_to_response(
    **path to the word file
    i_filename = 'WDP.txt'
    ** String Variable
      i_content = lw_xstring
    * File Type
    i_mime_type = 'NOTEPAD').

    同样的道理,利用client_window可以实现输出成XML等.

  • 相关阅读:
    关于centos防火墙
    linux基础命令
    mysql经典语句
    异常处理
    抽象类
    特性-多态
    特性-继承
    特性-封装
    python模块/文件/日期时间
    python函数3-函数嵌套/递归/匿名函数
  • 原文地址:https://www.cnblogs.com/caizjian/p/4362745.html
Copyright © 2011-2022 走看看