This repository was archived by the owner on Aug 5, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +17
-20
lines changed
Expand file tree Collapse file tree 1 file changed +17
-20
lines changed Original file line number Diff line number Diff line change 11const Excel = require ( 'exceljs' )
22const through = require ( 'through2' )
33const duplex = require ( 'duplexify' )
4- const Stream = require ( 'stream' )
5- const readable = new Stream . Readable ( )
64
75module . exports = ( ) => {
86 const input = through ( )
7+ const second = through ( )
98 const workbook = new Excel . Workbook ( )
10- readable . _read = ( ) => {
11- let headers = null
12- const reader = workbook . xlsx . read ( input )
13- . then ( ( worksheet ) => {
14- workbook . eachSheet ( ( sheet , id ) => {
15- sheet . eachRow ( ( row , id ) => {
16- if ( id === 1 ) {
17- headers = row . values
18- return
19- }
20- let item = { }
21- row . values . forEach ( ( v , k ) => {
22- item [ headers [ k ] ] = v
23- } )
24- readable . push ( JSON . stringify ( item ) )
9+
10+ let headers = null
11+ const reader = workbook . xlsx . read ( input )
12+ . then ( ( worksheet ) => {
13+ workbook . eachSheet ( ( sheet , id ) => {
14+ sheet . eachRow ( ( row , id ) => {
15+ if ( id === 1 ) {
16+ headers = row . values
17+ return
18+ }
19+ let item = { }
20+ row . values . forEach ( ( v , k ) => {
21+ item [ headers [ k ] ] = v
2522 } )
23+ second . push ( JSON . stringify ( item ) )
2624 } )
27- readable . push ( null )
2825 } )
29- }
30- return duplex ( input , readable )
26+ } )
27+ return duplex . obj ( input , second )
3128}
You can’t perform that action at this time.
0 commit comments