sheetjs-clone/demos/meteor/server/main.js

36 lines
1003 B
JavaScript
Raw Normal View History

/* xlsx.js (C) 2013-present SheetJS -- http://sheetjs.com */
2017-05-24 22:52:35 +00:00
import { Meteor } from 'meteor/meteor';
2017-09-24 23:40:09 +00:00
import { check } from 'meteor/check';
import XLSX from 'xlsx';
2017-05-24 22:52:35 +00:00
Meteor.methods({
/* read the data and return the workbook object to the frontend */
uploadS: (bstr, name) => {
2017-09-24 23:40:09 +00:00
check(bstr, String);
check(name, String);
return XLSX.read(bstr, { type: 'binary' });
},
uploadU: (ab, name) => {
check(ab, Uint8Array);
check(name, String);
return XLSX.read(ab, { type: 'array' });
},
2017-09-24 23:40:09 +00:00
download: (html) => {
check(html, String);
let wb;
if (html.length > 3) {
/* parse workbook if html is available */
wb = XLSX.read(html, { type: 'binary' });
} else {
/* generate a workbook object otherwise */
const data = [['a', 'b', 'c'], [1, 2, 3]];
const ws = XLSX.utils.aoa_to_sheet(data);
wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, 'SheetJS');
}
return wb;
},
2017-05-24 22:52:35 +00:00
});
Meteor.startup(() => { });