METHOD ONACTIONEXCEL .
DATA:
LO_NODE TYPE REF TO IF_WD_CONTEXT_NODE, "Node
LO_ELEM TYPE REF TO IF_WD_CONTEXT_ELEMENT, "element
LS_CONTEXT TYPE WD_THIS->ELEMENT_ZMMT014, "table of node
LT_CONTEXT TYPE WD_THIS->ELEMENTS_ZMMT014, "table of element
LW_STRING TYPE STRING,
LW_XSTRING TYPE XSTRING.
"Get node and get node table
LO_NODE = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_ZMMT014 ).
LO_NODE->GET_STATIC_ATTRIBUTES_TABLE( IMPORTING TABLE = LT_CONTEXT ).
"Header
CONCATENATE '领料单号' CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
'工厂' CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
'库位' CL_ABAP_CHAR_UTILITIES=>NEWLINE INTO LW_STRING.
"Item
LOOP AT LT_CONTEXT INTO LS_CONTEXT.
CONCATENATE LW_STRING
LS_CONTEXT-ZLLD CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
LS_CONTEXT-WERKS CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB
LS_CONTEXT-LGORT
CL_ABAP_CHAR_UTILITIES=>NEWLINE INTO LW_STRING.
ENDLOOP.
"Conversion string to xstring
CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
TEXT = LW_STRING
* MIMETYPE = ' '
ENCODING = ''"不指定字符会导致中文乱码
IMPORTING
BUFFER = LW_XSTRING
EXCEPTIONS
FAILED = .
"Download xstring file to client
WDR_TASK=>CLIENT_WINDOW->CLIENT->ATTACH_FILE_TO_RESPONSE(
I_FILENAME = 'WDP.xls'
I_CONTENT = LW_XSTRING
I_MIME_TYPE = 'EXCEL' ).
ENDMETHOD.