Loredra L
Loredra L

Reputation: 1553

Can Jsreport client asynchronous send and receive xlsx file?

I would like to use jsreport browser to send data to the server and download it back as xlsx file.

Using jsreport.download(request) would limit the amount of data cause it is a GET. Can I use jsreport.renderAsync() to download a xlsx file just like with pdf?

Upvotes: 0

Views: 478

Answers (1)

Jan Blaha
Jan Blaha

Reputation: 3095

jsreport.renderAsync returns in promise ArrayBuffer. You can convert it to blob and then use saveAs to download it to the user computer.

<script async="" src="https://cdn.rawgit.com/eligrey/FileSaver.js/e9d941381475b5df8b7d7691013401e171014e89/FileSaver.min.js"></script>

<script>
    jsreport.renderAsync({
        template: {
            content: '<table><tr><td>foo</td></tr></table>',
            engine: 'none',
            recipe: 'html-to-xlsx'
        }
    }).then(function (res) {
        var dataView = new DataView(res);
        var blob = new Blob([dataView], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
        saveAs(blob, 'a.xlsx')
    })
</script>

https://playground.jsreport.net/studio/workspace/HJ0z0yaY/8

Upvotes: 1

Related Questions