Skip to content

Commit c7cc341

Browse files
committed
- implement fixes/changes in issue #44 to correct zero becomming empty
- test syntax fixes
1 parent f460bde commit c7cc341

File tree

4 files changed

+20
-4
lines changed

4 files changed

+20
-4
lines changed

lib/worksheet.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ XlsxStreamReaderWorkSheet.prototype._handleWorkSheetNode = function (nodeData) {
226226
var index = parseInt(workingVal)
227227
workingVal = self.workBook._getSharedString(index)
228228

229-
self.workingRow.values[cellNum] = workingVal || ''
229+
self.workingRow.values[cellNum] = (workingVal || workingVal === 0) ? workingVal : ''
230230

231231
workingCell = {}
232232
break
@@ -269,7 +269,7 @@ XlsxStreamReaderWorkSheet.prototype._handleWorkSheetNode = function (nodeData) {
269269
}
270270
}
271271

272-
self.workingRow.values[cellNum] = workingVal || ''
272+
self.workingRow.values[cellNum] = (workingVal || workingVal === 0) ? workingVal : ''
273273

274274
workingCell = {}
275275
}

test/issue_44_empty_0.xlsx

9.62 KB
Binary file not shown.

test/test.js

+16
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,22 @@ describe('The xslx stream parser', function () {
125125
rows.length || done(new Error('Read nothing'))
126126
})
127127
})
128+
it('parse 0 as 0', function (done) {
129+
const workBookReader = new XlsxStreamReader()
130+
fs.createReadStream(path.join(__dirname, 'issue_44_empty_0.xlsx')).pipe(workBookReader)
131+
const rows = []
132+
workBookReader.on('worksheet', function (workSheetReader) {
133+
workSheetReader.on('end', function () {
134+
assert.strictEqual(rows[1][1], 0)
135+
assert.strictEqual(rows[1][2], 1)
136+
done()
137+
})
138+
workSheetReader.on('row', function (r) {
139+
rows.push(r.values)
140+
})
141+
workSheetReader.process()
142+
})
143+
})
128144
})
129145

130146
function consumeXlsxFile (cb) {

webpack.config.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ module.exports = {
77
fs: require('fs')
88
},
99
output: {
10-
filename: 'xlsx-stream-reader.bundle.js'
10+
filename: 'xlsx-stream-reader.bundle.js'
1111
}
12-
};
12+
}

0 commit comments

Comments
 (0)