Here’s a clean way to download your WD Table to Excel (Without Getting the Error:  “The file you are trying to open , ‘filename.xls’, is in a different format than

specified by the file extension. Verify that the file is not corrupted and is from a trusted source before opening the file. Do you want to open the file now? “”).

Create the following code in a method:

method wd_download_table_to_excel.
******************************************************************************************************************
*Purpose:  Accept any table and and sends to Excel from ABAP WebDynpro
******************************************************************************************************************
  data: lv_xstring type xstring.
  data: lv_mime_type type w3conttype.
  data: lv_mime_type_string type string.
  data: ref_data type ref to data.

  get reference of lt_tbl into ref_data.

  call function ‘SDOK_MIMETYPE_GET’
    exporting
      extension = ‘xlsx’
    importing
      mimetype  = lv_mime_type.

  lv_mime_type_string = lv_mime_type.

  cl_fdt_xl_spreadsheet=>if_fdt_doc_spreadsheet~create_document( exporting itab = ref_data iv_call_type = 1 columns = lt_column receiving xdocument = lv_xstring ).
  cl_wd_runtime_services=>attach_file_to_response( exporting i_filename = i_filename i_content = lv_xstring i_mime_type = lv_mime_type_string i_in_new_window = abap_false ).

endmethod.

Image of Method Below:

New NetWeaver Information at SAP.com

Very Helpfull

User Rating: Be the first one !