How to download created excel file in node js using exceljs

0 votes

I am using exceljs module for creating excel file. The problem is it is neither getting created nor getting saved in the path.

var excel = require('exceljs');
var options = {
    filename: './streamed-workbook.xlsx',
    useStyles: true,
    useSharedStrings: true
};

var workbook = new Excel.stream.xlsx.WorkbookWriter(options);
var sheet = workbook.addWorksheet('My Sheet');
worksheet.columns = [
    { header: 'Id', key: 'id', width: 10 },
    { header: 'Name', key: 'name', width: 32 },
    { header: 'D.O.B.', key: 'DOB', width: 10 }
];

worksheet.addRow({id: 1, name: 'John Doe', dob: new Date(1970,1,1)});
worksheet.addRow({id: 2, name: 'Jane Doe', dob: new Date(1965,1,7)});
worksheet.commit();

workbook.commit().then(function(){
    console.log('xls file is written.');
});

But when I run the code nothing happens. The excel is not created. What am I missing here?

*********************** Edit ************************** Made the following changes to my code but still its not working.

        var Excel = require('exceljs');
        var workbook = new Excel.Workbook();
        var worksheet = workbook.addWorksheet('My Sheet');
        worksheet.columns = [
            { header: 'Id', key: 'id', width: 10 },
            { header: 'Name', key: 'name', width: 32 },
            { header: 'D.O.B.', key: 'DOB', width: 10 }
        ];
        worksheet.addRow({id: 1, name: 'John Doe', dob: new Date(1970,1,1)});
        worksheet.addRow({id: 2, name: 'Jane Doe', dob: new Date(1965,1,7)});
        workbook.commit();
        workbook.xlsx.writeFile('./temp.xlsx').then(function() {
            // done
            console.log('file is written');
        });

Apr 4, 2022 in Database by gaurav
• 23,260 points
7,700 views

1 answer to this question.

0 votes
Download a sample Excel file using Node. js.
Overview of Node.js Excel File Download/Export. exceljs to build an Excel file.
Set up the Excel File Download project in Node.js.
Create a MySQL database and Sequelize it.
Sequelize should be started.
The Sequelize Model must be defined.
Create a download controller for an Excel file.
answered Apr 4, 2022 by Edureka
• 13,690 points

Related Questions In Database

0 votes
1 answer

How to download excel in response from api react.js

Create ReactJS project import React, { Component } ...READ MORE

answered Mar 31, 2022 in Database by gaurav
• 23,260 points
7,610 views
0 votes
1 answer

How to read a .xlsx file using the pandas Library in iPython?

Every sheet gets its own DataFrame, which ...READ MORE

answered Mar 25, 2022 in Database by anonymous
637 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
1,882 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,399 views
+1 vote
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,326 views
0 votes
1 answer

Save dynamically created table content in excel file using SheetJS

text inside tr instead of td in dynamic content. This results ...READ MORE

answered Apr 4, 2022 in Database by Edureka
• 13,690 points
3,544 views
0 votes
1 answer

How to create an excel file in android?

In Android, create Excel XLSX or XLS ...READ MORE

answered Apr 4, 2022 in Database by Edureka
• 13,690 points
1,209 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