Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js xlsx get number of non-empty rows

I use xlsx in Node.js application to get the number of total rows. Here is the code

const range = xlsx.utils.decode_range(sheet['!ref']);
const totalRows = (range.e.r - range.s.r) + 1;

The problem is it also counts formatted cells with empty text. I only want to get number of rows with non-empty text. How can I do it using xlsx or is there any other library that can count number of rows containing non-empty text?

like image 354
CherryBelle Avatar asked Oct 22 '25 09:10

CherryBelle


1 Answers

I know the thread is old but if anyone still looking for an answer, you can use the below code to ignore formatted blank cells:

var arr = xlsx.utils.sheet_to_row_object_array(sheet,{blankrows : false, defval: ''});
const totalRows = arr.length+1;
like image 70
Himanshu Jaswal Avatar answered Oct 24 '25 13:10

Himanshu Jaswal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!