From 43795a43bb1e26d7c9377badca88d5af13305ecd Mon Sep 17 00:00:00 2001 From: avrtau Date: Thu, 6 Jul 2017 14:55:10 -0400 Subject: [PATCH] Update SheetJS-vue.js --- demos/vue/SheetJS-vue.js | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/demos/vue/SheetJS-vue.js b/demos/vue/SheetJS-vue.js index 926d6b5..54a13e9 100644 --- a/demos/vue/SheetJS-vue.js +++ b/demos/vue/SheetJS-vue.js @@ -28,12 +28,28 @@ function s2ab(s) { Vue.component('html-preview', { template: SJSTemplate, methods: { + // as per: https://github.com/SheetJS/js-xlsx/wiki/Reading-XLSX-from-FileReader.readAsArrayBuffer() + // changing the readAsBinaryString (deprecated) to readAsArrayBuffer() onchange: function(evt) { + var file; + var files = evt.target.files; + + if (!files || files.length == 0) return; + + file = files[0]; + var reader = new FileReader(); reader.onload = function (e) { + // pre-process data + var binary = ""; + var bytes = new Uint8Array(e.target.result); + var length = bytes.byteLength; + for (var i = 0; i < length; i++) { + binary += String.fromCharCode(bytes[i]); + } + /* read workbook */ - var bstr = e.target.result; - var wb = XLSX.read(bstr, {type:'binary'}); + var wb = XLSX.read(binary, {type: 'binary'}); /* grab first sheet */ var wsname = wb.SheetNames[0]; @@ -48,7 +64,7 @@ Vue.component('html-preview', { document.getElementById('expor-table').style.visibility = "visible"; }; - reader.readAsBinaryString(evt.target.files[0]); + reader.readAsArrayBuffer(file); }, onexport: function(evt) { /* generate workbook object from table */