2017-09-05 05:26:50 +00:00
|
|
|
/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
|
2017-09-24 23:40:09 +00:00
|
|
|
import XLSX from 'xlsx';
|
|
|
|
|
|
|
|
import { Meteor } from 'meteor/meteor';
|
2017-05-24 22:52:35 +00:00
|
|
|
import { Template } from 'meteor/templating';
|
|
|
|
|
|
|
|
import './main.html';
|
|
|
|
|
2017-09-24 23:40:09 +00:00
|
|
|
Template.sheetjs.events({
|
|
|
|
'change input' (event) {
|
|
|
|
/* "Browser file upload form element" from SheetJS README */
|
|
|
|
const file = event.currentTarget.files[0];
|
|
|
|
const reader = new FileReader();
|
|
|
|
reader.onload = function(e) {
|
|
|
|
const data = e.target.result;
|
|
|
|
const name = file.name;
|
|
|
|
/* Meteor magic */
|
2021-09-20 07:37:16 +00:00
|
|
|
Meteor.call('uploadU', new Uint8Array(data), name, function(err, wb) {
|
2017-09-24 23:40:09 +00:00
|
|
|
if (err) throw err;
|
|
|
|
/* load the first worksheet */
|
|
|
|
const ws = wb.Sheets[wb.SheetNames[0]];
|
|
|
|
/* generate HTML table and enable export */
|
|
|
|
const html = XLSX.utils.sheet_to_html(ws, { editable: true });
|
|
|
|
document.getElementById('out').innerHTML = html;
|
|
|
|
document.getElementById('dnload').disabled = false;
|
|
|
|
});
|
|
|
|
};
|
2021-09-20 07:37:16 +00:00
|
|
|
reader.readAsArrayBuffer(file);
|
2017-09-24 23:40:09 +00:00
|
|
|
},
|
|
|
|
'click button' () {
|
|
|
|
const html = document.getElementById('out').innerHTML;
|
|
|
|
Meteor.call('download', html, function(err, wb) {
|
|
|
|
if (err) throw err;
|
|
|
|
/* "Browser download file" from SheetJS README */
|
2018-02-03 20:46:32 +00:00
|
|
|
XLSX.writeFile(wb, 'sheetjs.xlsx');
|
2017-09-24 23:40:09 +00:00
|
|
|
});
|
|
|
|
},
|
2017-05-24 22:52:35 +00:00
|
|
|
});
|
|
|
|
|