Split x-spreadsheet demo script [ci skip]

This commit is contained in:
reviewher 2021-10-05 10:57:19 -07:00
parent 12597dcf7b
commit 71160160d1
2 changed files with 38 additions and 37 deletions

@ -42,6 +42,7 @@ a { text-decoration: none }
<script src="https://unpkg.com/x-data-spreadsheet/dist/xspreadsheet.js"></script>
<script src="shim.js"></script>
<script src="xlsx.full.min.js"></script>
<script src="xlsxspread.js"></script>
<script>
/*jshint browser:true */
/* eslint-env browser */
@ -54,43 +55,6 @@ var xspr = x_spreadsheet(HTMLOUT);
HTMLOUT.style.height = (window.innerHeight - 400) + "px";
HTMLOUT.style.width = (window.innerWidth - 50) + "px";
function stox(wb) {
var out = [];
wb.SheetNames.forEach(function(name) {
var o = {name:name, rows:{}};
var ws = wb.Sheets[name];
var aoa = XLSX.utils.sheet_to_json(ws, {raw: false, header:1});
aoa.forEach(function(r, i) {
var cells = {};
r.forEach(function(c, j) { cells[j] = ({ text: c }); });
o.rows[i] = { cells: cells };
})
out.push(o);
});
return out;
}
function xtos(sdata) {
var out = XLSX.utils.book_new();
sdata.forEach(function(xws) {
var aoa = [[]];
var rowobj = xws.rows;
for(var ri = 0; ri < rowobj.len; ++ri) {
var row = rowobj[ri];
if(!row) continue;
aoa[ri] = [];
Object.keys(row.cells).forEach(function(k) {
var idx = +k;
if(isNaN(idx)) return;
aoa[ri][idx] = row.cells[k].text;
});
}
var ws = XLSX.utils.aoa_to_sheet(aoa);
XLSX.utils.book_append_sheet(out, ws, xws.name);
});
return out;
}
var process_wb = (function() {
var XPORT = document.getElementById('xport');

@ -0,0 +1,37 @@
function stox(wb) {
var out = [];
wb.SheetNames.forEach(function(name) {
var o = {name:name, rows:{}};
var ws = wb.Sheets[name];
var aoa = XLSX.utils.sheet_to_json(ws, {raw: false, header:1});
aoa.forEach(function(r, i) {
var cells = {};
r.forEach(function(c, j) { cells[j] = ({ text: c }); });
o.rows[i] = { cells: cells };
})
out.push(o);
});
return out;
}
function xtos(sdata) {
var out = XLSX.utils.book_new();
sdata.forEach(function(xws) {
var aoa = [[]];
var rowobj = xws.rows;
for(var ri = 0; ri < rowobj.len; ++ri) {
var row = rowobj[ri];
if(!row) continue;
aoa[ri] = [];
Object.keys(row.cells).forEach(function(k) {
var idx = +k;
if(isNaN(idx)) return;
aoa[ri][idx] = row.cells[k].text;
});
}
var ws = XLSX.utils.aoa_to_sheet(aoa);
XLSX.utils.book_append_sheet(out, ws, xws.name);
});
return out;
}