Reading Excel file using node js

0 votes

 i am using the FileUploader module to upload my file from angular to my REST API:

var uploader = $scope.uploader = new FileUploader({
    url: api.getUrl('uploadCompetence',null)
});

This is sent to the following POST function:

        router.route('/api/uploadCompetence')
        .post(function (req, res) {

        // This is where i want to read the file

            var competence = Competence.build(req.body.location);
            competence.add(function (success) {
                    res.json({message: 'quote created!'});
                },
                function (err) {
                    res.status(err).send(err);
                });
        })

My current objective is to read the excel file and add each row to my database thereafter.

I'm not exactly sure how I can read the file from Node, though.

Js, I've looked everywhere when debugging my server, but my Angular application is calling the API instead.

Nov 29, 2022 in Others by Kithuzzz
• 38,000 points
2,070 views

1 answer to this question.

0 votes

Several distinct libraries perform Excel file parsing (.xlsx). I'll mention two initiatives that I think are intriguing and worth investigating.

Node-xlsx

Excel parser and builder. It's kind of a wrapper for a popular project JS-XLSX, which is a pure javascript implementation from the Office Open XML spec.

node-xlsx project page

Example for parsing the file:

var xlsx = require('node-xlsx');

var obj = xlsx.parse(__dirname + '/myFile.xlsx'); // parses a file

var obj = xlsx.parse(fs.readFileSync(__dirname + '/myFile.xlsx')); // parses a buffer

ExcelJS

Data and styles from spreadsheets can be read, edited, and written to XLSX and JSON. It is an ongoing project. The most recent commit has been made nine hours prior to this writing. Although I haven't personally tried it myself, the api seems robust and offers a wide range of possibilities.

exceljs project page

Code example:

// read from a file
var workbook = new Excel.Workbook();
workbook.xlsx.readFile(filename)
    .then(function() {
        // use workbook
    });

// pipe from stream
var workbook = new Excel.Workbook();
stream.pipe(workbook.xlsx.createInputStream());
answered Dec 10, 2022 by narikkadan
• 63,600 points

Related Questions In Others

0 votes
0 answers

Creating an Instagram bot with reading an excel file and posing on Instagram, but some of words can not be read properly

from instabot import Bot import openpyxl import smtplib bot = ...READ MORE

Sep 26, 2022 in Others by Kithuzzz
• 38,000 points
808 views
0 votes
1 answer

Calculating the mean and std on excel file using python

Use pandas to do this: import pandas as pd df = ...READ MORE

answered Nov 4, 2022 in Others by narikkadan
• 63,600 points
2,231 views
0 votes
1 answer

How to convert pdf file to excel file using python

Just specify your whole output path instead ...READ MORE

answered Nov 4, 2022 in Others by narikkadan
• 63,600 points
4,174 views
0 votes
1 answer
0 votes
1 answer

Unable to download excel file from src/assets in development/qa/prod environment for angular application

Try this: this.HttpClient.get("./assets/sample.xlsx",{responseType: "blob"}).subscribe((res:any) => ...READ MORE

answered Nov 12, 2022 in Others by narikkadan
• 63,600 points
3,640 views
0 votes
1 answer

What are the vulnerability related to PHP Form?

Hii, The $_SERVER["PHP_SELF"] variable can be used by ...READ MORE

answered Feb 13, 2020 in PHP by Niroj
• 82,840 points
3,195 views
+1 vote
1 answer

How can we send message multiple time to a specific person or group in whatsapp using loop?

Hii @kartik,  This is simple task to send single ...READ MORE

answered Feb 28, 2020 in Java-Script by Niroj
• 82,840 points
18,664 views
0 votes
1 answer

Why it is necessary to refresh CSRF token per form request?

Hello, Generating a new CSRF token for each ...READ MORE

answered Mar 19, 2020 in Laravel by Niroj
• 82,840 points
4,563 views
0 votes
1 answer

Removing specific rows in an Excel file using Azure Data Factory

Under the 'Source' tab, choose the number ...READ MORE

answered Sep 23, 2022 in Others by narikkadan
• 63,600 points
2,574 views
0 votes
1 answer

How can I convert excel file to pdf using TCPDF?

PHPExcel can only read charts from Excel2007 ...READ MORE

answered Oct 21, 2022 in Others by narikkadan
• 63,600 points
2,145 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP