Skip to content
This repository has been archived by the owner on Jul 25, 2021. It is now read-only.

Commit

Permalink
add fix for "createSheet" types
Browse files Browse the repository at this point in the history
  • Loading branch information
clarketm committed May 2, 2017
1 parent eb0a3d2 commit cf6caf0
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/stable/js/tableexport.js
Original file line number Diff line number Diff line change
Expand Up @@ -485,24 +485,29 @@
createSheet: function (data) {
var ws = {};
var range = {s: {c: 10000000, r: 10000000}, e: {c: 0, r: 0}};
for (var R = 0; R != data.length; ++R) {
for (var C = 0; C != data[R].length; ++C) {
var types = TableExport.prototype.types;
for (var R = 0; R !== data.length; ++R) {
for (var C = 0; C !== data[R].length; ++C) {
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;
var cell = {v: data[R][C]};
if (cell.v == null) continue;
var cell = data[R][C];
if (!cell || !cell.v) continue;
var cell_ref = XLSX.utils.encode_cell({c: C, r: R});

if (typeof cell.v === 'number') cell.t = 'n';
else if (typeof cell.v === 'boolean') cell.t = 'b';
else if (cell.v instanceof Date) {
if (!cell.t) {
if (types.number.assert(cell.v)) cell.t = 'n';
else if (types.boolean.assert(cell.v)) cell.t = 'b';
else if (types.date.assert(cell.v)) cell.t = 'd';
else cell.t = 's';
}

if (cell.t === 'd') {
cell.t = 'n';
cell.z = XLSX.SSF._table[14];
cell.v = this.dateNum(cell.v);
}
else cell.t = 's';

ws[cell_ref] = cell;
}
Expand All @@ -528,7 +533,7 @@
string2ArrayBuffer: function (s) {
var buf = new ArrayBuffer(s.length);
var view = new Uint8Array(buf);
for (var i = 0; i != s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
for (var i = 0; i !== s.length; ++i) view[i] = s.charCodeAt(i) & 0xFF;
return buf;
},
/**
Expand All @@ -540,7 +545,7 @@
* @param extension {String} file extension
*/
export2file: function (data, mime, name, extension) {
if (XLSX && extension.substr(0, 4) == ".xls") {
if (XLSX && extension.substr(0, 4) === ".xls") {
var wb = new this.Workbook(),
ws = this.createSheet(data);

Expand Down

0 comments on commit cf6caf0

Please sign in to comment.