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.

Create empty Workbook unsing NodeJS

See original GitHub issue

I’ve already installed js-xlsx with:

npm install xlsx

How do I create an empty Workbook using nodejs?

Example:

XLSX = require('xlsx');
var wb =  new XLSX.Workbook(); // This won't work.

I want to create a new Workbook to load data from a database and then save it.

Thanks.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:5
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

13reactions
waylonflinncommented, Dec 7, 2016

I ran into this too. So, I made a module to make it easier to create new workbooks and do simple editing of existing workbooks.

https://github.com/waylonflinn/xlsx-workbook

Here’s a snippet from the docs:

// the Workbook object gives you more control and stores multiple sheets 
var Workbook = require('xlsx-workbook').Workbook;
 
var workbook = new Workbook();
 
var sales = workbook.add("Sales");
var costs = workbook.add("Costs");
 
sales[0][0] = 304.50;
sales[1][0] = 159.24;
sales[2][0] = 493.38;
 
costs[0][0] = 102.50;
costs[1][0] = 59.14;
costs[2][0] = 273.32;
 
// automatically appends the '.xlsx' extension 
workbook.save("Revenue-Summary");
9reactions
rodwcommented, Feb 9, 2016

Hi @arthurspa, just picked up js-xlsx this evening so there may well be a better answer, but following the example at http://sheetjs.com/demos/writexlsx.html I’ve noticed that something like:

var wb = { SheetNames:[], Sheets:{} };

seems to be a sufficient to initialize a Workbook object.

That is, any object (map) with a SheetNames array and Sheets map can (when SheetNames and Sheets are correctly populated) be saved as described at https://github.com/SheetJS/js-xlsx#writing-workbooks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to create a new sheet in an existing xlsx file using xlsx ...
I would like to do something like this (this is done by using the Excel JS package): const sheet = workbookStream.addSheet('sheet1'); ... but ......
Read more >
SheetJS Tutorial - Create xlsx with Javascript - Red Stapler
Now let's start with creating a new workbook by calling book_new() utility function which will return an empty workbook object.
Read more >
Generate Excel with Node.js - Pagorn Phusaisakul
Basic usage of sheetjs (xlsx package for Node.js). “Generate Excel with Node.js” is published by Pagorn Phusaisakul.
Read more >
Read/Write Excel File in Node.js using XLSX
How to create an excel sheet using JSON data. Step 1: Install the XLSX package using npm or bower npm i --save xlsx...
Read more >
Beginner's Guide to exceljs. Handling spreadsheet data in ...
For your information, some of the features in exceljs are highly dependent on node.js built-in packages. For example, the save file ...
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