Reputation: 89
I want to read excel to save in MySQL database by using NodeJS. I do not know what library to use. I want to be able to read excel based on certain rows and columns. Please help me.
Upvotes: 2
Views: 5272
Reputation: 5148
There are many libraries that you can use :
etc.
Upvotes: 1
Reputation: 137
There's a great library SheetJS/js-xlsx that provides an API for reading Excel documents.
For example, if you are uploading a file, you'll end up with something like this:
var XLSX = require('xlsx');
function importFromExcel(file) {
var reader = new FileReader();
reader.onload = function (e) {
/* read workbook */
var bstr = e.target.result;
var workbook = XLSX.read(bstr, { type: 'binary' });
/* for each sheet, grab a sheet name */
workbook.SheetNames.forEach(function (workSheetName, index) {
var sheetName = workbook.SheetNames[index];
var workSheet = workbook.Sheets[sheetName];
var excelData = (XLSX.utils.sheet_to_json(workSheet, { header: 1 }));
mapExcelData(excelData); // do whatever you want with your excel data
});
};
reader.readAsBinaryString(file);
}
function mapExcelData(data) {...}
Upvotes: 0