I'm successfully reading my Excel file in React by following this SO thread as.
var reader = new FileReader();
reader.onload = function (e) {
var data = e.target.result;
let readedData = XLSX.read(data, {type: 'binary'});
const wsname = readedData.SheetNames[0];
const ws = readedData.Sheets[wsname];
/* Converts a worksheet object to an array of JSON objects*/
const parsedData = XLSX.utils.sheet_to_json(ws, {header:1});
console.log(parsedData);
}
reader.readAsBinaryString(fileName)
But having a simple problem, i.e., it's reading empty rows as well and causing empty entries in array.
Output of console.log(parsedData); in the above code is

I know a quick hack is to remove empty entries from the array but I want to know a better approach to avoid this problem even happening.
Edit - It's "blankrows" and not "blankRows"
I did a search and came across a similar question on gitmemory here, which shows that there's a blankRows property you can set to false in order to skip blank rows, which would look like this with your implementation:
/* Converts a worksheet object to an array of JSON objects*/
const parsedData = XLSX.utils.sheet_to_json(ws, {
header:1,
blankrows: false
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With