2017-03-25 01:36:40 +00:00
|
|
|
function sheet_to_workbook(sheet/*:Worksheet*/, opts)/*:Workbook*/ {
|
|
|
|
var n = opts && opts.sheet ? opts.sheet : "Sheet1";
|
|
|
|
var sheets = {}; sheets[n] = sheet;
|
|
|
|
return { SheetNames: [n], Sheets: sheets };
|
|
|
|
}
|
|
|
|
|
|
|
|
function aoa_to_sheet(data/*:AOA*/, opts/*:?any*/)/*:Worksheet*/ {
|
|
|
|
var o = opts || {};
|
2017-04-09 04:03:19 +00:00
|
|
|
if(DENSE != null && o.dense == null) o.dense = DENSE;
|
2017-04-08 06:55:35 +00:00
|
|
|
var ws/*:Worksheet*/ = o.dense ? ([]/*:any*/) : ({}/*:any*/);
|
2017-03-25 01:36:40 +00:00
|
|
|
var range/*:Range*/ = ({s: {c:10000000, r:10000000}, e: {c:0, r:0}}/*:any*/);
|
|
|
|
for(var R = 0; R != data.length; ++R) {
|
|
|
|
for(var C = 0; C != data[R].length; ++C) {
|
|
|
|
if(typeof data[R][C] === 'undefined') continue;
|
|
|
|
var cell/*:Cell*/ = ({v: data[R][C] }/*:any*/);
|
|
|
|
if(range.s.r > R) range.s.r = R;
|
|
|
|
if(range.s.c > C) range.s.c = C;
|
|
|
|
if(range.e.r < R) range.e.r = R;
|
|
|
|
if(range.e.c < C) range.e.c = C;
|
|
|
|
if(cell.v === null) { if(!o.cellStubs) continue; cell.t = 'z'; }
|
|
|
|
else if(typeof cell.v === 'number') cell.t = 'n';
|
|
|
|
else if(typeof cell.v === 'boolean') cell.t = 'b';
|
|
|
|
else if(cell.v instanceof Date) {
|
|
|
|
cell.z = o.dateNF || SSF._table[14];
|
2017-04-03 00:16:03 +00:00
|
|
|
if(o.cellDates) { cell.t = 'd'; cell.w = SSF.format(cell.z, datenum(cell.v)); }
|
|
|
|
else { cell.t = 'n'; cell.v = datenum(cell.v); cell.w = SSF.format(cell.z, cell.v); }
|
2017-03-25 01:36:40 +00:00
|
|
|
}
|
|
|
|
else cell.t = 's';
|
2017-04-08 06:55:35 +00:00
|
|
|
if(o.dense) {
|
|
|
|
if(!ws[R]) ws[R] = [];
|
|
|
|
ws[R][C] = cell;
|
|
|
|
} else {
|
|
|
|
var cell_ref = encode_cell(({c:C,r:R}/*:any*/));
|
|
|
|
ws[cell_ref] = cell;
|
|
|
|
}
|
2017-03-25 01:36:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(range.s.c < 10000000) ws['!ref'] = encode_range(range);
|
|
|
|
return ws;
|
|
|
|
}
|
|
|
|
|