进阶-案例九: WD中实现export 到Excel,Doc,Txt.

1、导出excel 文件代码

进阶-案例九: WD中实现export 到Excel,Doc,Txt.

导出事件代码:

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 =
OTHERS = .
* 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等.

上一篇:android SDK Manager 上载失败


下一篇:failure injection