zsusac / ReactHTMLTableToExcel

Convert HTML table to Excel file and download
MIT License
103 stars 59 forks source link

not work with large data #20

Open Augustzyh opened 5 years ago

Augustzyh commented 5 years ago

Unable to download when the amount of data is too large, browser reported network error.

Augustzyh commented 5 years ago

I solved the problem ,and I hope author can update this component, there is solution: 1.add func to index.js: function dataURLtoBlob(dataurl) { var arr = dataurl.split(',') var _arr = arr[1].substring(0, arr[1].length - 2) var mime = arr[0].match(/:(.*?);/)[1], bstr = atob(_arr), n = bstr.length, u8arr = new Uint8Array(n) while (n--) { u8arr[n] = bstr.charCodeAt(n) } return new Blob([u8arr], { type: mime, }) }

2.modify a.herf to blob: var base64 = uri + ReactHTMLTableToExcel.base64(ReactHTMLTableToExcel.format(template, context)) element.href = URL.createObjectURL(dataURLtoBlob(base64))

Now u can download big data.

and if u want to change the ssuffix of download file, u just need modify var filename = String(this.props.filename) + '.xls' to var filename = String(this.props.filename) + '.xlsx' at code 124 in index.js

shahabahmed1 commented 3 years ago

I solved the problem ,and I hope author can update this component, there is solution: 1.add func to index.js: function dataURLtoBlob(dataurl) { var arr = dataurl.split(',') var _arr = arr[1].substring(0, arr[1].length - 2) var mime = arr[0].match(/:(.*?);/)[1], bstr = atob(_arr), n = bstr.length, u8arr = new Uint8Array(n) while (n--) { u8arr[n] = bstr.charCodeAt(n) } return new Blob([u8arr], { type: mime, }) }

2.modify a.herf to blob: var base64 = uri + ReactHTMLTableToExcel.base64(ReactHTMLTableToExcel.format(template, context)) element.href = URL.createObjectURL(dataURLtoBlob(base64))

Now u can download big data.

and if u want to change the ssuffix of download file, u just need modify var filename = String(this.props.filename) + '.xls' to var filename = String(this.props.filename) + '.xlsx' at code 124 in index.js

I wanted to change the suffix and did the same in index.js (for me its line 74), but it is still downloading in '.xls' extension