question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Excel file is not created nor saved

See original GitHub issue

I am following the documentation to create an excel workbook and add worksheet to it. This is my code:

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

However, it does not create any excel file. Nothing happens. What am I doing wrong here?

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
neeraj87commented, Jan 7, 2017

Its working finally.

try {
        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)});

        var tempFilePath = tempfile('.xlsx');
        workbook.xlsx.writeFile(tempFilePath).then(function() {
            console.log('file is written');
            res.sendFile(tempFilePath, function(err){
                console.log('---------- error downloading file: ' + err);
            });
        });
    } catch(err) {
        console.log('OOOOOOO this is the error: ' + err);
    }
0reactions
esinecancommented, Dec 20, 2017

This isn’t the same though. You’re not using streaming api anymore.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to troubleshoot errors when you save Excel workbooks
Possible reasons why documents don't save ... Select the tab that applies to you, or go to the "Quick resolution" section. ... If...
Read more >
Don't Panic! Here's How to Recover an Excel File Not Saved
To restore your new file without any saved updates, open Microsoft Excel first. Then, click Open on the File tab on the Ribbon....
Read more >
Microsoft Excel Document not saved error [Fixed]
Save the Excel workbook with a new filename. · Move the original workbook to a new workbook. · Terminate the interrupting program or...
Read more >
2 ways to recover unsaved Excel files - Journal of Accountancy
For the first scenario described above, the way to recover your never-before-saved file is to, first, open Microsoft Excel. Then go to the...
Read more >
Fix Excel File Error 'Unable to Save Excel Workbook'
There may be an issue with the Build version or the Registry Values settings may not be appropriate, which does not allow the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found