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

table2excel

v1.0.4

Published

convert and download html tables to a xlsx-file that can be opened in Microsoft Excel

Downloads

1,130

Readme

table2excel

table2excel is a ecma5 compiled vanilla javascript plugin to convert and download html tables to a xlsx-file that can be opened in Microsoft Excel.

It uses the awesome js-xlsx plugin from Sheet JS as a dependency. Thanks!

Demo

Quick Start

<script src="table2excel.js"></script>

<script>
  var table2excel = new Table2Excel();
  table2excel.export(document.querySelectorAll("table"));
</script>

Node

// npm install table2excel --save
import 'table2excel';
const Table2Excel = window.Table2Excel;

const table2excel = new Table2Excel(options);

See my webpack configuration to see how to get js-xlsx running with webpack in the browser.

Additional options

You can pass in options as a parameter like new Table2Excel(options). The currently supported options are:

  • defaultFileName: The general file name of a downloaded document. Default: 'file'. Can also be adjusted individually for export as a second parameter, e.g. table2excel.export(table, "cool table");.
  • tableNameDataAttribute: Data attribute name to identify the worksheet name of a table. Default: 'excel-name'. Usage: <table data-excel-name="Check this out">...</table>. If not set, worksheets are numbered incrementally from 1.

Cell type handlers

table2excel detects a few special cells by default to display them correctly in Excel:

  • Numbers
  • Inputs: for input[type="text"], select or textarea elements
  • Dates: tries to parse the date or set the exact timestamp via data-timestamp on the cell (recommended!)
  • Booleans: parses 'true', 'false' or checkboxes/radios without text to booleans
  • Lists: parses <ul>...</ul> or <ol>...</ol> list elements to '..., ...'

Everything else will just get displayed as simple text. You can easily though add custom type handlers for your own needs:

Table2Excel.extend((cell, cellText) => {
  // {HTMLTableCellElement} cell - The current cell.
  // {string} cellText - The inner text of the current cell.

  // cell should be described by this type handler
  if (selector) return {
    t: ...,
    v: ...,
  };

  // skip and run next handler
  return null;
});

The return value must be a js-xlsx cell object.

Contributing

If you would like to submit a pull request with any changes you make, please feel free! Simply run npm test to test and npm start to compile before submitting pull requests.

Issues

Please use the GitHub issue tracker to raise any problems or feature requests.