Skip to content

Instantly share code, notes, and snippets.

// Uses excel4node version 1.x.x
var xl = require('excel4node');
var wb = new xl.Workbook({
dateFormat: 'm/d/yy hh:mm:ss'
});
var ws = wb.addWorksheet('Dates');
@natergj
natergj / manyRows.js
Created February 3, 2018 21:23
generate generate excel file with 50,000 rows of 13 columns open
const xl = require('excel4node');
// Create workbook and add worksheet
const wb = new xl.Workbook();
const ws = wb.addWorksheet('Data', {
disableRowSpansOptimization: true,
});
// Generate some fake data for testing
const data = [];
@natergj
natergj / background color
Created April 23, 2018 23:33
excel4node set background color in cell
// Require library
const xl = require('excel4node');
// Create a new instance of a Workbook class
const wb = new xl.Workbook();
// Add Worksheets to the workbook
const ws = wb.addWorksheet('Background Color');
// create a style with solid background color
@natergj
natergj / wrapText.js
Created May 22, 2019 21:27
Text wrapping code snippet
const xl = require("excel4node");
const wb = new xl.Workbook();
const ws = wb.addWorksheet("Sheet1");
ws.cell(2, 5, 2, 11, true)
.string(
"There is a flower within my heart, Daisy, Daisy! Planted one day by a glancing dart, Planted by Daisy Bell! Whether she loves me or loves me not, Sometimes it's hard to tell; Yet I am longing to share the lot Of beautiful Daisy Bell!"
)
.style({
alignment: {
wrapText: true
@natergj
natergj / percenatage formatting
Created February 13, 2018 00:12
display cells as percentage in excel4node
var xl = require('excel4node');
var wb = new xl.Workbook();
var ws = wb.addWorksheet('test');
// Create a reusable style
var style = wb.createStyle({
numberFormat: '#.00%; -#.00%; -'
});
@natergj
natergj / excel4node express.js example
Created November 8, 2015 22:15
Very basic express.js app to create a route that generates and downloads a basic Excel workbook
var express = require('express');
var xl = require('excel4node');
var app = express();
app.get('/', function(req, res){
res.end('Hello World');
});
app.get('/myreport', function(req, res) {
async function excelDataFiller(rowNumber) {
const startIndex = 2;
const j = rowNumber + 1;
const numDiff = getCountDiff(storage.allCountResults[rowNumber].csdbCount, storage.allCountResults[rowNumber].esCount);
const perDiff = (storage.allCountResults[rowNumber].csdbCount - storage.allCountResults[rowNumber].esCount) / storage.allCountResults[rowNumber].csdbCount;
/* Column parameters */
ws.column(1).setWidth(30);
ws.column(2).setWidth(27);
@natergj
natergj / bg_color_font.js
Created July 25, 2019 13:57
excel4node background color and font
const xl = require("excel4node");
const wb = new xl.Workbook();
const ws = wb.addWorksheet("Background Color");
const greenBgColumnsRows = wb.createStyle({
font: { color: "black", size: 12 },
fill: {
type: "pattern",
patternType: "solid",
bgColor: "#33FF35",
const xl = require('excel4node');
const costsObj = {
'supplies': {
'paper': 100,
'toner': 50,
},
'equipment': {
'laptops': 3500,
'accessories': 150
@natergj
natergj / freeze.js
Created October 19, 2018 12:30
Freeze 1st row on 2nd sheet only
const xl = require('excel4node')
const wb = new xl.Workbook()
const ws1 = wb.addWorksheet('sheet 1')
ws1.cell(1, 1).string('Sheet 1 - A1')
ws1.cell(5, 1).string('Sheet 1 - A5')
ws2 = wb.addWorksheet('sheet 2')
ws2.cell(1, 1).string('Sheet 2 - A1')