This document explains how to:
Download Microsoft Excel from CRM Web UI
- Create a BSP Controller "downloadExcel" for Excel.
- Create a Controller class "ZCL_CRM_DOWNLOAD_EXCEL" with superclass CL_BSP_CONTROLLER2. Redefine the DO_REQUEST method with the below code.
METHOD do_request.
ENDMETHOD.
DATA:
lv_xls TYPE xstring.
lv_len TYPE i.
lv_len TYPE i.
* Get the excel file here. For more details, you can refer the definition of the following method in How to - Add Custom XML Parts to Microsoft Excel using ABAP
get_xls_download(
IMPORTING
ev_xml_xstring_xls = lv_xls
EXCEPTIONS
error_occurred = 1
).
lv_len = xstrlen( lv_xls ).
IMPORTING
ev_xml_xstring_xls = lv_xls
EXCEPTIONS
error_occurred = 1
).
lv_len = xstrlen( lv_xls ).
* Export response data
CALL METHOD response->if_http_entity~append_data
EXPORTING
data = lv_xls
length = lv_len.
CALL METHOD response->if_http_entity~append_data
EXPORTING
data = lv_xls
length = lv_len.
* Set response content-type as Excel
CALL METHOD response->if_http_entity~set_header_field
EXPORTING
name = 'content-type' "#EC NOTEXT
CALL METHOD response->if_http_entity~set_header_field
EXPORTING
name = 'content-type' "#EC NOTEXT
"content-type for XLSX
value = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'.
value = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'.
"Content types
"Excel (*.xlsx) - 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
"Excel (*.xlsm) - application/vnd.ms-excel.sheet.macroenabled.12'
ENDMETHOD.
3. Set the contoller class to the BSP Controller. Now you can use this controller to download the file.
