Skip to navigation
Javascript download json request with excel example
31.10.19
1. npm install xlsx npm install file-saver 2. on the jqgrid add: }).jqGrid('navButtonAdd', '#grid_toppager', { caption: "Download", id:"download", buttonicon: "fa-file-excel-o", onClickButton: download 3. function download (e) { let styles = sum_styles(window.orders); let ws_data = [['foo','bar','master']]; let error = false; let res = JSON.parse(this.response); let date = get_date(); for(let i in res['rows']) { let style = res['rows'][i]['key']; if(styles.hasOwnProperty(style)) { let a = [ style, styles[style]['pco'], styles[style]['wa'], styles[style]['wso'] ]; ws_data.push(a); } } let wb = XLSX.utils.book_new(); wb.Props = { Title: "Foo", Subject: "Bar", Author: "Master", CreatedDate: date }; wb.SheetNames.push("export_1"); let ws = XLSX.utils.aoa_to_sheet(ws_data); let wscols = [ {wch:50}, {wch:15}, {wch:15} ]; ws['!cols'] = wscols; let wsrows = [ {hpx:35} ]; ws['!rows'] = wsrows; wb.Sheets["export_1"] = ws; let wbout = XLSX.write(wb, {bookType:'xlsx', type: 'binary'}); saveAs(new Blob([s2ab(wbout)],{type:"application/octet-stream"}), 'foo-'+date+'.xlsx'); }
https://www.npmjs.com/package/xlsx
Reply
Anonymous
Information Epoch 1732617553
There is no perfect productivity system.
Home
Notebook
Contact us