cancel
Showing results for 
Search instead for 
Did you mean: 

Issue in downloading data into Excel/CSV in Web UI

Former Member
0 Kudos

Hi gurus,

I am working on a requirement where I need to download some data into Excel or CSV format. I have a custom button in the BSP page and i wrote the below code in the associated event handler.

Even Handler


    "lv_output is already filled with the data. 
    "Convert the string into xstring.
    CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
      EXPORTING
        text     = lv_output
        mimetype = 'APPLICATION/MSEXCEL'
      IMPORTING
        buffer   = lv_x_output.
    "Find the length of the xls file.
    lv_xls_len = XSTRLEN( lv_x_output ).
    response->set_header_field( name = 'Content-Type' value = 'APPLICATION/MSEXCEL' ).
    "Some Browsers have caching problems when loading Excel Format
    response->delete_header_field( name = if_http_header_fields=>cache_control ).
    response->delete_header_field( name = if_http_header_fields=>expires ).
    response->delete_header_field( name = if_http_header_fields=>pragma ).
    "Start Excel viewer either in the Browser or as a separate window
    response->set_header_field( name = 'Content-Disposition'
                                value = 'attachment; filename=export.xls' ).
    response->set_data( data = lv_x_output
                        length = lv_xls_len ).
    navigation->response_complete( ).

(Thanks to SDN forums and blogs for the above code)

The issue i am facing:

Instead of opening the excel file, the content of the excel is getting displayed in the same window. Can you kindly reply if you have any solution or suggestions to 'open' the excel instead of getting displayed in the window of the browser.

I tried to create url of the excel file using the below code and used javascript window.open("url") in the corresponding bsp page, to the open the excel.

Event Handler


"create the url
CONCATENATE runtime->application_url '/' lv_guid_32 'xls'
INTO gv_display_url.

"upload the content into application server cache 
cl_http_server=>server_cache_upload( url = gv_display_url
response = response ).

(gv_display_url is a static attribute declared in the corresponding implementation class).

View.htm


"inside java script
window.open("<%=>zl_***_impl=>gv_display_url%>").focus();

This method worked for a few times. But most of the time, the window is getting closed immediately without opening the excel. When i checked in ICM Monitor (Tx:SMICM, Goto->HTTP Server Cache), i was able to see and open the excel file, which means excel file got created and saved in the application server cache successfully.

Kindly help.

Thanks and regards,

Arun N K.

Accepted Solutions (0)

Answers (2)

Answers (2)

0 Kudos

Hi Arun,

the issue is with HTTP session I guess you can try out one thing in window.open("<%=>zl_***_impl=>gv_display_url%>",""<%=sy-uzeit%>) here you just need to pass on the time so now automatically window will open without any issue as this will correspond to new HTTP session

Please check and let me know if it works.

Former Member
0 Kudos

Hi,

The issue is related to 'window.open("url")'. I replaced the above function with another script window.navigation("url).

When 'window.navigation' script is executed, browser is asking a security question whether to download the content or not. If i click yes, whole window is refreshed and existing data is gone. This happens only for first time when we try to download. After this the download is working fine without any session time out, if we are using the same window.

Kindly help if you have any inputs regarding the issue.

Thanks a lot.

Regards,

Arun N K.