Answer the question
In order to leave comments, you need to log in
How to parse an excel file?
Hello I want to read excel file cell value and using
xlsx https://www.npmjs.com/package/xlsx
Wrote
function excel2json(buffer) {
function getFirstDigitPosition(str) {
let i = 0;
for (; str[i] < '0' || str[i] > '9'; i++);
return i == str.length ? -1 : i;
}
let workbook = XLSX.read(buffer, { type: "buffer" });
let sheetNamesList = workbook.SheetNames;
sheetNamesList.forEach(function (sheetName) {
let worksheet = workbook.Sheets[sheetName];
for (let cellName in worksheet) {
if (cellName[0] === "!") continue;
let numberPosition = getFirstDigitPosition(cellName);
let colName = cellName.substring(0, numberPosition);
let rowNumber = parseInt(cellName.substring(numberPosition));
let cellValue = worksheet[cellName].v;
console.log("\n" + cellName + ":" + cellValue); //A1:�� ࡱ �????????????????>? ?�� вместо нормальной строчки
}
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question