2

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.

1
  • You need to show your work. What have you looked for? Its is not possible that you haven't found a "library" to read excel or connect to mysql unless you didn't look for it. Just googling "nodejs excel" gives a lot of good results. Do that. Choose a library, do some code, and if you are stuck with that, then post that code here. People will help if you show some efforts. Commented Jul 10, 2018 at 4:41

2 Answers 2

1

There are many libraries that you can use :

  1. sheetjs/xlsx
  2. excel.js

etc.

Sign up to request clarification or add additional context in comments.

Comments

0

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) {...} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.