进阶-案例九: 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等.

 

转载于:https://www.cnblogs.com/caizjian/p/4362745.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值