Hi WDA mates,
I need to create a button to extract table data into a excel (xls) spreadsheet.
How do I get the exactly cells configuration from the table into the xls? Also I need to get the header into the excel file.
Here is the table I need to extract. This is the standard WDA component GRFN_SURVEY_RESPONSE (survey_response view).
![Screenshot_1.png]()
Here is my code.
method onactionexport_to_excel .
data lo_nd_questions type ref to if_wd_context_node.
data lo_el_questions type ref to if_wd_context_element.
data lt_questions type wd_this->elements_questions.
data ls_questions type wd_this->element_questions.
data text type string.
data xtext type xstring.
data lv_mime type mimetypes-type.
* navigate from <CONTEXT> to <SFLIGHT> via lead selection
lo_nd_questions = wd_context->get_child_node( name = wd_this->wdctx_questions ).
* get all declared attributes
lo_nd_questions->get_static_attributes_table(
importing
table = lt_questions ).
loop at lt_questions into ls_questions.
concatenate text ls_questions-text
ls_questions-comments
ls_questions-zcomments_rev
cl_abap_char_utilities=>newline
"cl_abap_char_utilities=>cr_lf
into text. "separated by cl_abap_char_utilities=>horizontal_tab.
endloop.
call function 'SDOK_MIMETYPE_GET'
exporting
extension = '.XLS'
importing
mimetype = lv_mime.
call function 'SCMS_STRING_TO_XSTRING'
exporting
text = text
encoding = '4103'
importing
buffer = xtext.
concatenate cl_abap_char_utilities=>byte_order_mark_little xtext into xtext in byte mode.
call method cl_wd_runtime_services=>attach_file_to_response
exporting
i_filename = 'Download.xls'
* i_filename = lv_filename
i_content = xtext
i_mime_type = 'EXCEL'
i_in_new_window = abap_false
i_inplace = abap_false.
endmethod.
Here is what I'm getting into the xls:
![Screenshot_2.png]()
Thank you