Skip to content

Commit 69b867e

Browse files
committed
Edit docs, add standard for code style, bulk npm version
1 parent ab715fd commit 69b867e

12 files changed

+2543
-832
lines changed

README.md

+34-33
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# xlsx-stream-reader
2+
3+
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
4+
25
======
36

47
Memory efficinet minimalist streaming XLSX reader that can handle piped
@@ -79,57 +82,56 @@ fs.createReadStream(fileName).pipe(workBookReader);
7982

8083
```
8184

82-
8385
Beta Warning
86+
8487
-------
8588
This module is currently in use on a live internal business system for product
8689
management. That being said this should still be considered beta. More usage
8790
and input from users will be needed due to the numerous differences/incompatibilities/flukes
8891
I have already run into with XLSX files.
8992

90-
9193
Limitations
94+
9295
-------
9396
The row reader currently returns stored values for formulas (these are normally available)
9497
and does not calculate the formula itself. As time permits the row handler will be more capable
9598
but was enough for currrent purposes (loading values from large worksheets fast)
9699

97-
98-
99100
Inspiration
101+
100102
-----------
101-
Need a simple XLSX file streaming reader to handle large excel sheets but only
102-
one available/compatible was by guyonroche/exceljs. The stream reader module at
103-
the time was unfinished/unusable and rewrite attempts exposed column shifting I
103+
Need a simple XLSX file streaming reader to handle large excel sheets but only
104+
one available/compatible was by guyonroche/exceljs. The stream reader module at
105+
the time was unfinished/unusable and rewrite attempts exposed column shifting I
104106
could not solve
105107

106-
107108
More Information
109+
108110
-----------
109-
Events are emmited as pertinent parts of the workbook and worksheet are receieved
110-
in the stream. Theoretically you could pause the input stream if events are being
111+
Events are emmited as pertinent parts of the workbook and worksheet are receieved
112+
in the stream. Theoretically you could pause the input stream if events are being
111113
receieved too fast but this has not been tested
112114

113-
Events can potentially (even though I have not seen it) be receieved out of order,
114-
if you receive a worksheet end event while still receieving rows be sure to make sure
115+
Events can potentially (even though I have not seen it) be receieved out of order,
116+
if you receive a worksheet end event while still receieving rows be sure to make sure
115117
your number of rows receieved equals the `workSheetReader.rowCount`
116118

117-
Theoretically you could process an excel sheet as it is being uploaded, depending
118-
on the sheet type, but untried (I encountered some XLSX files that have a different
119-
zip format that requires having the entire file to read the archive contents properly),
119+
Theoretically you could process an excel sheet as it is being uploaded, depending
120+
on the sheet type, but untried (I encountered some XLSX files that have a different
121+
zip format that requires having the entire file to read the archive contents properly),
120122
but still probably better to save temp first and read streasm from there.
121123

122-
Currently if the zip archive does not have the shared strings at the begining of the
123-
archive then the input stream for each sheet is pied into a temp file until the shared
124-
string are encountered and processed, then re-read the temp worksheets with the shared
125-
strings.
126-
124+
Currently if the zip archive does not have the shared strings at the begining of the
125+
archive then the input stream for each sheet is pied into a temp file until the shared
126+
string are encountered and processed, then re-read the temp worksheets with the shared
127+
strings.
127128

128129
API Information
130+
129131
-----------
130132
#### new XlsxStreamReader()
131133

132-
Create a new XlsxStreamReader object (workBookReader). After attaching handlers you
134+
Create a new XlsxStreamReader object (workBookReader). After attaching handlers you
133135
can `pipe()` your input stream into the reader to begin processing
134136

135137
#### Event: 'error'
@@ -150,7 +152,7 @@ are available via array `workBookReader.workBookSharedStrings`.
150152

151153
#### Event: 'styles'
152154

153-
After the workbook styles have been parsed this event is emmited. Styles are available
155+
After the workbook styles have been parsed this event is emmited. Styles are available
154156
via array `workBookReader.workBookStyles`
155157

156158
#### Event: 'worksheet'
@@ -161,8 +163,8 @@ Emmitted when a worksheet is reached. The sheet number is availble via
161163
{Number} `workSheetReader.id`. You can either process or skip at this point,
162164
but you must do one for the processing to the next sheet to continue/finish.
163165

164-
Once event is recieved you can attach worksheet on handlers (end, row) then you
165-
would `workSheetReader.process()`. If you do not want to process a sheet and instead
166+
Once event is recieved you can attach worksheet on handlers (end, row) then you
167+
would `workSheetReader.process()`. If you do not want to process a sheet and instead
166168
want to skip entirely, you would `workSheetReader.skip()` without attaching any handlers.
167169

168170
#### Worksheet Event: 'end'
@@ -178,44 +180,43 @@ Emmitted on every row encountered in the worksheet. for more details on what
178180
is in the row object attributes, see the [Row class][msdnRows] on MSDN.
179181

180182
For example:
183+
181184
* `row.values`: sparse array containing all cell values
182185
* `row.formulas`: sparse array containing all cell formulas
183186
* `row.attributes.r`: row index
184187
* `row.attributes.ht`: Row height measured in point size
185188
* `row.attributes.customFormat`: '1' if the row style should be applied.
186189
* `row.attributes.hidden`: '1' if the row is hidden
187190

188-
189191
References
192+
190193
-----------
191194
* [Working with sheets (Open XML SDK)][msdnSheets]
192195
* [Row class][msdnRows]
193196
* [ExcelJS][ExcelJS]
194197

195-
196198
Used Modules
199+
197200
-----------
198201
* [Path][modPath]
199202
* [Util][modUtil]
200203
* [Stream][modStream]
201204
* [Sax][modSax]
202-
* [Unzip2][modUnzip2]
205+
* [unzipper][modUnzipper]
203206
* [Temp][modTemp]
204207

205-
206208
Authors
209+
207210
-----------
208-
Written by [Brian Taber](https://github.com/DaSpawn)
211+
Written by [Brian Taber](https://github.com/DaSpawn) and [Kirill Husyatin](https://github.com/kikill95)
209212

210213
[![DaSpawn's Gratipay][gratipay-image-daspawn]][gratipay-url-daspawn]
211214

212-
213215
License
216+
214217
-----------
215218
[MIT](LICENSE)
216219

217-
218-
219220
[gratipay-url-daspawn]: https://gratipay.com/~DaSpawn
220221
[gratipay-image-daspawn]: https://img.shields.io/gratipay/team/daspawn.svg
221222
[msdnRows]: https://msdn.microsoft.com/EN-US/library/office/documentformat.openxml.spreadsheet.row.aspx
@@ -226,5 +227,5 @@ License
226227
[modStream]: https://nodejs.org/api/stream.html
227228
[modUtil]: https://nodejs.org/api/util.html
228229
[modSax]: https://github.com/isaacs/sax-js
229-
[modUnzip2]: https://github.com/glebdmitriew/node-unzip-2
230+
[modUnzipper]: https://github.com/ZJONSSON/node-unzipper
230231
[modTemp]: https://github.com/bruce/node-temp

example/example1.js

+32-33
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,45 @@
22
* xlsx-stream-reader
33
* Copyright(c) 2016 Brian Taber
44
* MIT Licensed
5-
*
5+
*
66
* example1
7-
*
7+
*
88
*/
99

10-
'use strict';
10+
'use strict'
1111

12+
const fs = require('fs')
13+
const XlsxStreamReader = require('../')
1214

13-
const fs = require("fs");
14-
const XlsxStreamReader = require("../");
15-
16-
var workBookReader = new XlsxStreamReader();
15+
var workBookReader = new XlsxStreamReader()
1716
workBookReader.on('error', function (error) {
18-
throw(error);
19-
});
17+
throw (error)
18+
})
2019

2120
workBookReader.on('worksheet', function (workSheetReader) {
22-
if (workSheetReader.id > 1){
23-
// we only want first sheet
24-
console.log("Skip Worksheet:",workSheetReader.id)
25-
workSheetReader.skip();
26-
return;
27-
}
28-
console.log("Worksheet:",workSheetReader.id)
29-
30-
workSheetReader.on('row', function (row) {
31-
row.values.forEach(function(rowVal, colNum){
32-
console.log("RowNum", row.attributes.r, "colNum", colNum, "rowValLen", rowVal.length, "rowVal", "'" + rowVal + "'")
33-
});
34-
});
35-
36-
workSheetReader.on('end', function () {
37-
console.log("Worksheet",workSheetReader.id,"rowCount:",workSheetReader.rowCount)
38-
});
39-
40-
// call process after registering handlers
41-
workSheetReader.process();
42-
});
21+
if (workSheetReader.id > 1) {
22+
// we only want first sheet
23+
console.log('Skip Worksheet:', workSheetReader.id)
24+
workSheetReader.skip()
25+
return
26+
}
27+
console.log('Worksheet:', workSheetReader.id)
28+
29+
workSheetReader.on('row', function (row) {
30+
row.values.forEach(function (rowVal, colNum) {
31+
console.log('RowNum', row.attributes.r, 'colNum', colNum, 'rowValLen', rowVal.length, 'rowVal', "'" + rowVal + "'")
32+
})
33+
})
34+
35+
workSheetReader.on('end', function () {
36+
console.log('Worksheet', workSheetReader.id, 'rowCount:', workSheetReader.rowCount)
37+
})
38+
39+
// call process after registering handlers
40+
workSheetReader.process()
41+
})
4342
workBookReader.on('end', function () {
44-
console.log("finished!")
45-
});
43+
console.log('finished!')
44+
})
4645

47-
fs.createReadStream('example/example1.xlsx').pipe(workBookReader);
46+
fs.createReadStream('example/example1.xlsx').pipe(workBookReader)

example/example2.js

+32-33
Original file line numberDiff line numberDiff line change
@@ -2,46 +2,45 @@
22
* xlsx-stream-reader
33
* Copyright(c) 2016 Brian Taber
44
* MIT Licensed
5-
*
5+
*
66
* example1
7-
*
7+
*
88
*/
99

10-
'use strict';
10+
'use strict'
1111

12+
const fs = require('fs')
13+
const XlsxStreamReader = require('../')
1214

13-
const fs = require("fs");
14-
const XlsxStreamReader = require("../");
15-
16-
var workBookReader = new XlsxStreamReader();
15+
var workBookReader = new XlsxStreamReader()
1716
workBookReader.on('error', function (error) {
18-
throw(error);
19-
});
17+
throw (error)
18+
})
2019

2120
workBookReader.on('worksheet', function (workSheetReader) {
22-
if (workSheetReader.id > 1){
23-
// we only want first sheet
24-
console.log("Skip Worksheet:",workSheetReader.id)
25-
workSheetReader.skip();
26-
return;
27-
}
28-
console.log("Worksheet:",workSheetReader.id)
29-
30-
workSheetReader.on('row', function (row) {
31-
row.values.forEach(function(rowVal, colNum){
32-
console.log("RowNum", row.attributes.r, "colNum", colNum, "rowValLen", rowVal.length, "rowVal", "'" + rowVal + "'")
33-
});
34-
});
35-
36-
workSheetReader.on('end', function () {
37-
console.log("Worksheet",workSheetReader.id,"rowCount:",workSheetReader.rowCount)
38-
});
39-
40-
// call process after registering handlers
41-
workSheetReader.process();
42-
});
21+
if (workSheetReader.id > 1) {
22+
// we only want first sheet
23+
console.log('Skip Worksheet:', workSheetReader.id)
24+
workSheetReader.skip()
25+
return
26+
}
27+
console.log('Worksheet:', workSheetReader.id)
28+
29+
workSheetReader.on('row', function (row) {
30+
row.values.forEach(function (rowVal, colNum) {
31+
console.log('RowNum', row.attributes.r, 'colNum', colNum, 'rowValLen', rowVal.length, 'rowVal', "'" + rowVal + "'")
32+
})
33+
})
34+
35+
workSheetReader.on('end', function () {
36+
console.log('Worksheet', workSheetReader.id, 'rowCount:', workSheetReader.rowCount)
37+
})
38+
39+
// call process after registering handlers
40+
workSheetReader.process()
41+
})
4342
workBookReader.on('end', function () {
44-
console.log("finished!")
45-
});
43+
console.log('finished!')
44+
})
4645

47-
fs.createReadStream('example2.xlsx').pipe(workBookReader);
46+
fs.createReadStream('example2.xlsx').pipe(workBookReader)

0 commit comments

Comments
 (0)