diff --git a/source/lib/cell/index.js b/source/lib/cell/index.js index caa6494..6baabf0 100644 --- a/source/lib/cell/index.js +++ b/source/lib/cell/index.js @@ -84,22 +84,28 @@ function numberSetter(val) { } function booleanSetter(val) { - if (val === undefined || typeof (val.toString().toLowerCase() === 'true' || ((val.toString().toLowerCase() === 'false') ? false : val)) !== 'boolean') { - throw new TypeError(util.format('Value sent to Bool function of cells %s was not a bool, it has type of %s and value of %s', - JSON.stringify(this.excelRefs), - typeof (val), - val - )); + if (val !== true && val !== false) { + let valString = val.toString().toLowerCase(); + if (valString === "true") { + val = true; + } else if (valString === "false") { + val = false; + } else { + throw new TypeError(util.format('Value sent to Bool function of cells %s was not a bool, it has type of %s and value of %s', + JSON.stringify(this.excelRefs), + typeof (val), + val + )); + } } - val = val.toString().toLowerCase() === 'true'; if (!this.merged) { this.cells.forEach((c, i) => { - c.bool(val.toString()); + c.bool(val ? '1' : '0'); }); } else { var c = this.cells[0]; - c.bool(val.toString()); + c.bool(val ? '1' : '0'); } return this; } diff --git a/tests/cell.test.js b/tests/cell.test.js index 11d5dbd..74a3d3a 100644 --- a/tests/cell.test.js +++ b/tests/cell.test.js @@ -59,7 +59,7 @@ test('Add Boolean to cell', (t) => { let thisCell = ws.cells[cell.excelRefs[0]]; t.ok(thisCell.t === 'b', 'cellType set to boolean'); t.ok(typeof (thisCell.v) === 'string', 'cell Value is a string'); - t.ok(thisCell.v === 'true' || thisCell.v === 'false', 'Cell value value is correct'); + t.ok(thisCell.v === '1' || thisCell.v === '0', 'Cell value value is correct'); }); test('Add Formula to cell', (t) => {