File tree 4 files changed +22
-3
lines changed
4 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -45,7 +45,8 @@ function XlsxStreamReaderWorkBook (options) {
45
45
workBookInfo : {
46
46
value : {
47
47
sheetRelationships : { } ,
48
- sheetRelationshipsNames : { }
48
+ sheetRelationshipsNames : { } ,
49
+ date1904 : false
49
50
} ,
50
51
writable : true ,
51
52
enumerable : false
@@ -344,6 +345,8 @@ XlsxStreamReaderWorkBook.prototype._parseWorkBookInfo = function (nodeData) {
344
345
nodeData . forEach ( function ( data ) {
345
346
if ( data . name === 'sheet' ) {
346
347
self . workBookInfo . sheetRelationshipsNames [ data . attributes [ 'r:id' ] ] = data . attributes . name
348
+ } else if ( data . name === 'workbookPr' && data . attributes && data . attributes . date1904 === '1' ) {
349
+ self . workBookInfo . date1904 = true
347
350
}
348
351
} )
349
352
}
Original file line number Diff line number Diff line change @@ -248,17 +248,18 @@ XlsxStreamReaderWorkSheet.prototype._handleWorkSheetNode = function (nodeData) {
248
248
if ( self . options . formatting && workingVal ) {
249
249
if ( self . workBook . hasFormatCodes ) {
250
250
var formatId = workingCell . attributes . s ? self . workBook . xfs [ workingCell . attributes . s ] . attributes . numFmtId : 0
251
+ var date1904 = self . workBook . workBookInfo . date1904
251
252
if ( typeof formatId !== 'undefined' ) {
252
253
var format = self . workBook . formatCodes [ formatId ]
253
254
if ( typeof format === 'undefined' ) {
254
255
try {
255
- workingVal = ssf . format ( Number ( formatId ) , Number ( workingVal ) )
256
+ workingVal = ssf . format ( Number ( formatId ) , Number ( workingVal ) , { date1904 } )
256
257
} catch ( e ) {
257
258
workingVal = ''
258
259
}
259
260
} else if ( format !== 'General' ) {
260
261
try {
261
- workingVal = ssf . format ( format , Number ( workingVal ) )
262
+ workingVal = ssf . format ( format , Number ( workingVal ) , { date1904 } )
262
263
} catch ( e ) {
263
264
workingVal = ''
264
265
}
Original file line number Diff line number Diff line change @@ -49,6 +49,21 @@ describe('The xslx stream parser', function () {
49
49
workSheetReader . process ( )
50
50
} )
51
51
} )
52
+ it ( 'supports date formate 1904' , function ( done ) {
53
+ var workBookReader = new XlsxStreamReader ( )
54
+ fs . createReadStream ( path . join ( __dirname , 'date1904.xlsx' ) ) . pipe ( workBookReader )
55
+ const rows = [ ]
56
+ workBookReader . on ( 'worksheet' , function ( workSheetReader ) {
57
+ workSheetReader . on ( 'end' , function ( ) {
58
+ assert ( rows [ 1 ] [ 2 ] === '27/09/1986' )
59
+ done ( )
60
+ } )
61
+ workSheetReader . on ( 'row' , function ( r ) {
62
+ rows . push ( r . values )
63
+ } )
64
+ workSheetReader . process ( )
65
+ } )
66
+ } )
52
67
it ( 'catches zip format errors' , function ( done ) {
53
68
var workBookReader = new XlsxStreamReader ( )
54
69
fs . createReadStream ( path . join ( __dirname , 'notanxlsx' ) ) . pipe ( workBookReader )
You can’t perform that action at this time.
0 commit comments