npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

excel-help

v1.0.3

Published

Helper + Middleware for exporting excel files based on sheetjs

Downloads

34

Readme

Excel Help

Helper + Middleware for exporting excel files based on sheetjs

Installation

npm install excel-help

Include

Include into js app using common js.

const excelHelp = require("excel-help")

Usage

Excel Help can be used in two ways.

  1. As an express js middleware - To quickly export some data comig from an api as Excel File.
  2. As a standalone helper - To aid in creating worksheets and workspaces

Middleware

Usage

app.use(excelHelp.middleware);

The middleware accepts data in following format to quickly export a json array) or an array of arrays or both and provides a function res.xlsx to export it as a file / stream.

res.xlsx("export.xlsx",  [
  {
    "type": "json",
     "data": [{
       "foo":"bar",
       "bar":"foo",
       "abc":"def"
     },
     {
        "foo":"xyz", 
        "bar":"lak",
        "abc":"mkx"
     }]
},
{
  "type": "columns",
  "data": [
    ["yqmxc", "kqyui", "zhasi", "kljhda"],
    ["yqmxl", "kqyuiads", "zhasida", null, new Date()]
   ]
}
], config?config:{})

alt text

It accepts an array of objects of folklowing format:

{
	"type" :  //"json" or "columns",
	"data": //the data //Array of objects //Array of arrays,
	"options" // options object (Not Mandatory)
}
options
  • If type is "columns" options
  • If type is "json" We can use the in built sheetjs options along with these options
    • headerMap - headerMap is an object which can be used to transform the column names. By default the key of the data object is considered as the header.

      {headerMap: {"foo":"FOO","bar":"BAR"}}
      • excludeHeaders - excludeHeaders is an array of headers that one wants to exclude from the export.
config

config may contain the workbook configuration as defined config

Standalone

Usage

const ExcelHelp = require("excel-help");
let excelHelpWb = new ExcelHelp().addSheet(
[
  {
    "type": "json",
     "data": [{
       "foo":"bar",
       "bar":"foo",
       "abc":"def"
     },
     {
        "foo":"xyz", 
        "bar":"lak",
        "abc":"mkx"
     }]
},
{
  "type": "columns",
  "data": [
    ["yqmxc", "kqyui", "zhasi", "kljhda"],
    ["yqmxl", "kqyuiads", "zhasida", null, new Date()]
   ]
}
],
"sheet1",     //Name of the sheet (Not Mandatory)

config?config:{}    // config object (NotMandatory)

)
.addSheet(
[
 {
    "type": "json",
      "data": [
        {
          "foo":"xyz",
          "bar":"lak",
          "abc":"mkx"
        }
      ]
   }
 ],

"sheet2",   //Name of the sheet (Not Mandatory)

config?config:{}   // config object (NotMandatory)

)
.build() 

The method addSheet can be chained any no of times to add muliple sheets to the workbook. addSheet contains a config option which might be used to do operations on the worksheet like changing the width or merging columns.

Changing Column Widths

{"!cols": [ { wch: 10 } ]}

Other examples can be found on sheetjs

The build functions returns the workbook object . The user can then proced to modify the workbook as he needs or write the workbook

Example

new ExcelHelp().XLSX.writeFile(excelHelpWb, filename, write_opts)