Skip to content Skip to sidebar Skip to footer

Import Data From Excel To Mysql With Node Js

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

Solution 1:

There are many libraries that you can use :

  1. sheetjs/xlsx
  2. excel.js

etc.

Solution 2:

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');

functionimportFromExcel(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);
}

functionmapExcelData(data) {...} 

Post a Comment for "Import Data From Excel To Mysql With Node Js"