Support cells for the 'd' date type

This commit is contained in:
Hugues Malphettes 2014-02-15 11:15:10 +08:00
parent 2cb06e0fb8
commit a66ff4462e
3 changed files with 25 additions and 0 deletions

@ -63,6 +63,11 @@ function parse_ws_xml(data, opts) {
case '1': case 'TRUE': case "true": case true: p.v=true; break;
default: throw "Unrecognized boolean: " + p.v;
} break;
case 'd':
var epoch = Date.parse(p.v);
p.v = (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000);
p.t = 'n';
break;
/* in case of error, stick value in .raw */
case 'e': p.raw = RBErr[p.v]; break;
default: throw "Unrecognized cell type: " + p.t;

15
test.js

@ -201,3 +201,18 @@ describe('should have core properties and custom properties parsed', function()
assert.equal(wb.Custprops.Counter, -3.14);
});
});
describe.skip('should parse a sheet with a d date cell', function() {
var wb, ws;
before(function() {
XLSX = require('./');
wb = XLSX.readFile('./test_files/xlsx-stream-d-date-cell.xlsx');
// wb = XLSX.readFile('./test_files/xlsx-stream-array.xlsx');
var sheetName = 'Sheet1';
ws = wb.Sheets[sheetName];
});
it('Must have read the date', function() {
var sheet = XLSX.utils.sheet_to_row_object_array(ws);
assert.equal(sheet[3]['てすと'], '2/14/14');
});
});

@ -1349,6 +1349,11 @@ function parse_ws_xml(data, opts) {
case '1': case 'TRUE': case "true": case true: p.v=true; break;
default: throw "Unrecognized boolean: " + p.v;
} break;
case 'd':
var epoch = Date.parse(p.v);
p.v = (epoch - new Date(Date.UTC(1899, 11, 30))) / (24 * 60 * 60 * 1000);
p.t = 'n';
break;
/* in case of error, stick value in .raw */
case 'e': p.raw = RBErr[p.v]; break;
default: throw "Unrecognized cell type: " + p.t;