Skip to content

Instantly share code, notes, and snippets.

@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) {
@natergj
natergj / excel4node http native sample
Created November 24, 2015 00:45
Very basic sample using node's native http module
var xl = require('excel4node');
var http = require('http');
http.createServer(function(req, res){
switch(req.url){
case '/download':
var wb = new xl.WorkBook();
var ws = wb.WorkSheet('Sheet 1');
ws.Cell(1,1).String('String');
wb.write('Excel.xlsx', res);
// 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 / DataValidationIssue161
Created January 15, 2018 15:41
Attempt to recreate the behavior described in https://github.com/natergj/excel4node/issues/161
const xl = require('excel4node');
const wb = new xl.Workbook();
const ws = wb.addWorksheet('sheet1');
const ws2 = wb.addWorksheet('sheet2');
ws2.cell(1,1).string('value 1');
ws2.cell(2,1).string('value 2');
ws2.cell(3,1).string('value 3');
@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 / 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 / Indian currency
Created February 21, 2018 00:50
display currency in Indian format in excel4node
var xl = require('excel4node');
var wb = new xl.Workbook();
var ws = wb.addWorksheet('test');
var indianCurrency = wb.createStyle({
numberFormat: '[>=10000000]"RS "##\\,##\\,##\\,##0;[>=100000]"RS "\\ ##\\,##\\,##0;"RS "##,##0',
});
ws.column(1).setWidth(15);
ws.cell(1,1).number(12.34).style(indianCurrency); // displays as "RS 12"
@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
const xl = require('excel4node');
const costsObj = {
'supplies': {
'paper': 100,
'toner': 50,
},
'equipment': {
'laptops': 3500,
'accessories': 150
@natergj
natergj / Hidden First Tab
Created September 30, 2018 22:57
hide first tab for workbooks created with excel4node
const xl = require('excel4node');
const wb = new xl.Workbook({
workbookView: {
activeTab: 1,
},
});
const hiddenWorksheet = wb.addWorksheet('Hidden', {
hidden: true,