How to export my json data into pdf,excel using angular 2

前端 未结 4 906
慢半拍i
慢半拍i 2021-01-05 13:52

I have created my Data table from the angular 2 website. Now I want to export my json data to PDF,excel using angular 2 framework.

Kindly give me s

4条回答
  •  太阳男子
    2021-01-05 14:10

    I was finally used this one:

        function downloadExcelFile(ev) {
            connectionService.getExcelExport(function (response) {
                if (response.status == 200) {
    
                    /** 
                     * Export data to csv file
                     */
                    let blob = new Blob([response.data], {type: 'text/csv'});
                    let filename = `export.csv`;
                    if(window.navigator.msSaveOrOpenBlob) {
                        window.navigator.msSaveBlob(blob, filename);
                    }
                    else{
                        let elem = window.document.createElement('a');
                        elem.href = window.URL.createObjectURL(blob);
                        elem.download = filename;
                        document.body.appendChild(elem);
                        elem.click();
                        document.body.removeChild(elem);
                    }
    
                    console.log(`export excel file is successful.`);
                }
            })
        }
    

提交回复
热议问题