ffalt / xlsx-extract

nodejs lib for extracting data from XLSX files
MIT License
45 stars 17 forks source link

Is there a way to stop the read until I have finished a preprocessing task? #315

Open foward opened 4 years ago

foward commented 4 years ago

Is there a way to stop the read until I have finished a preprocessing task?

new XLSX() .extract("../excel_source/Software List_1.2.xlsm", { sheet_name: "Products", ignore_header: 0 }) // or sheet_name or sheet_nr .on("sheet", function (sheet) { console.log("sheet", sheet); //sheet is array [sheetname, sheetid, sheetnr] }) .on("row", function (row) { // here can we do a continue or something like that in order to read the next row?

Thanks

MuLoo commented 3 years ago

i have almost same problem, i just want read the first row. e.g. the header line of xlsx file. i wonder if there is a way to stop read whole file ?

i have to throw a error when trigger 'row' like this

new XLSX().extract(path, { sheet_nr: 1})
.on('row', function (row) {
  // i got first row then throw error manually
  throw Error('stop')
})
.on('error', function(error) {
  console.log(error)
})
combuilder commented 2 years ago

i have almost same problem, i just want read the first 200 rows and insert into mysql. i wonder if there is a way to stop read next 200 row in the xlsx sheet?

How to get the xlsx stream, and pause / resume this stream???

santosh-sambhavani commented 2 years ago

You can do this

let tmp = new XLSX().extract(path, { sheet_nr: 1})

tmp.on('row', function (row) { if(termination_condition) { tmp.emit('end'); } }) .on('end', function() {

})