Excel Recipe to show in browser via hosted API



  • Hi, I am using the hosted API and trying to show an Excel report in the browser. It works great in the studio.

    When I try to use it via the API, it just downloads the Excel file and doesn't show it in Excel Online. I am sure I am just missing something...

    I am using Python (django), here is a snippet of how I return the data:

    report = requests.post(url, data=body, headers=headers, auth=auth)
    response = HttpResponse(report)
    response['Content-type'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
    return response
    

    I can get PDF's to work great by changing the content-type to 'application/pdf'

    Should I have a wrapper or something around the Excel data to preview it online?


  • administrators

    hi!

    I can get PDF's to work great by changing the content-type to 'application/pdf'

    i guess that you are trying to show the server response inside an iframe, right? this works nice when using pdf because browsers these days have built-in support for previewing pdf files. but when dealing with excel you need to use other techniques because the browser will not preview the excel as something built-in in an iframe.

    I am using the hosted API and trying to show an Excel report in the browser. It works great in the studio.

    yes, the reason that the excel browser preview works nicely in studio is because we have some code that makes the excel file available to the excel online page when a report request was done from jsreport studio (request.options.preview in the linked code is true when a request comes from studio). technically you can achieve the excel browser preview in you app in the same way that we do by hosting your excel file in some of your servers, then make it available at some public url and the return an iframe with a content similar like this.

    another option for you is to configure jsreport and your template to always render in preview mode. you can do that by using a script that set this for your template.

    function beforeRender (req, res, done) {
      req.options.preview = true
      done()
    }
    

    then configure the xlsx publicUriForPreview option in jsreport config to point to a public url that is hosting your excel files. by doing that jsreport will automatically send the excel file that you are rendering to publicUriForPreview (check the details about what your publicUriForPreview needs to handle ("GET/POST requests"9 in order to be able to fit in this flow) and then respond with an iframe that loads the excel online page using your publicUriForPreview page to load the excel file.

    hope this help you.



  • Yes that helps, what I was really missing was the simple idea that you are using the Office Online viewer, so I just reference that:: https://view.officeapps.live.com/op/view.aspx?src={}
    Note that you have to escape out the URL for the source, I am sure you do that in the above suggestion.

    thanks for the response.


Log in to reply
 

Looks like your connection to jsreport forum was lost, please wait while we try to reconnect.