Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tableexport

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tableexport

The simple, easy-to-implement plugin to export HTML tables to xlsx, xls, csv, and txt files

  • 4.0.0-rc.5
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.6K
decreased by-22.59%
Maintainers
1
Weekly downloads
 
Created
Source

Build Status

TableExport

The simple, easy-to-implement plugin to export HTML tables to xlsx, xls, csv, and txt files

TableExport demo -- TableExport + RequireJS skeleton -- TableExport + Flask skeleton.

v4.0.0-rc.5 Release Candidate:

Notice: In May 2017, v3.0.0 will be superceded by v4.0.0. Althought this is a major version bump, fear not, because all changes will be 100% backwards-compatible.

So why the major version bump you ask? Well, the rationale for a major version bump is that due to a change in TableExport's dependencies, in v4.0.0 forth, JQuery will no longer be a required dependency, instead it will be purely optional. So existing implementations with jQuery will continue to work unimpeded, now with the added benefit that new projets no longer need to rely on the overhead of such large library, unless of course you prefer jQuery or it is already part of your project.

Examples:

Property
Settings
TODOs
  • Update JSDocs and TypScript definition file.
  • Allow ignoreCSS and emptyCSS to work with any selector|selector[] instead of solely a single CSS class.
  • Fix bug with CSV and TXT ignoreRows and ignoreCols (rows/cols rendered as empty strings rather than being removed).
  • Reimplement and test the update, reset, and remove TableExport prototype roperties without requiring jQuery.
  • Ensure (via testing) full consistency and backwards-compatibility for jQuery.
  • Make jQuery as peer dependency and ensure proper TableExport rendering in broswser, AMD, and CommonJS environments.

Getting Started (v3.3.12 LTS)

Download and Setup

To use this plugin, include the jQuery library, FileSaver.js script, and TableExport.js plugin before the closing <body> tag of your HTML document:

<script src="jquery.js"></script>
<script src="FileSaver.js"></script>
 ...
<script src="tableexport.js"></script>

Install with Bower

$ bower install tableexport.js

Install with npm

$ npm install tableexport

CDNjs

uncompressedcompressed
CSS🔗🔗
JS🔗🔗
Images🔗xlsx🔗xls🔗csv🔗txt

unpkg

uncompressedcompressed
CSS🔗🔗
JS🔗🔗
Images🔗xlsx🔗xls🔗csv🔗txt

Dependencies

Required:

* jQuery dependency requirement is removed as of 4.0.0-alpha.2

Optional / Theming:
Add-Ons:

In order to provide Office Open XML SpreadsheetML Format ( .xlsx ) support, you must include the following third-party script to your project before FileSaver.js and TableExport.js.

<script src="xlsx.core.js"></script>
<script src="FileSaver.js"></script>
 ...
<script src="tableexport.js"></script>
Older Browsers:

To support older browsers ( Chrome < 20, Firefox < 13, Opera < 12.10, IE < 10, Safari < 6 ) include the Blob.js polyfill before the FileSaver.js script.

Until Safari provides native support for either the HTML5 download attribute or service workers, limited xlx and xlsx support is provided by including the Blob.js polyfill, albeit the filename will always be labeled Unknown.

<script src="xlsx.core.js"></script>
<script src="Blob.js"></script>
<script src="FileSaver.js"></script>
 ...
<script src="tableexport.js"></script>

Usage

CSS

By default, TableExport.js utilizes the Bootstrap CSS framework to deliver enhanced table and button styling. For non-Bootstrap projects, initialize with the bootstrap property set to false.

$("table").tableExport({
    bootstrap: false
});

When used along with Bootstrap, there are four custom classes .xlsx, .xls, .csv, .txt providing button styling for each of the exportable filetypes.

JavaScript

To use the export plugin, just call:

$("table").tableExport();

Additional properties can be passed in to customize the look and feel of your tables, buttons, and exported data.

Notice that by default, TableExport will create export buttons for three different filetypes xls, csv, txt. You can choose which buttons to generate by setting the formats property to the filetypes of your choice.

/* Defaults */
$("table").tableExport({
    headings: true,                     // (Boolean), display table headings (th/td elements) in the <thead>
    footers: true,                      // (Boolean), display table footers (th/td elements) in the <tfoot>
    formats: ["xls", "csv", "txt"],     // (String[]), filetype(s) for the export
    filename: "id",                     // (id, String), filename for the downloaded file
    bootstrap: true,                    // (Boolean), style buttons using bootstrap
    position: "bottom",                 // (top, bottom), position of the caption element relative to table
    ignoreRows: null,                   // (Number, Number[]), row indices to exclude from the exported file(s)
    ignoreCols: null,                   // (Number, Number[]), column indices to exclude from the exported file(s)
    ignoreCSS: ".tableexport-ignore",   // (selector, selector[]), selector(s) to exclude cells from the exported file(s)
    emptyCSS: ".tableexport-empty",     // (selector, selector[]), selector(s) to replace cells with an empty string in the exported file(s)
    trimWhitespace: false               // (Boolean), remove all leading/trailing newlines, spaces, and tabs from cell text in the exported file(s)
});

Note: to use the xlsx filetype, you must include the third-party scripts listed in the Dependencies section.

TableExport supports additional methods (update, reset and remove) to control it after creation.

/* Run plugin and save it to a variable */
var tables = $("table").tableExport();
/* update */
tables.update({
    filename: "newFile"     // pass in a new set of properties
});

/* reset */
tables.reset();             // useful for a dynamically altered table

/* remove */
tables.remove();            // removes caption and buttons

Properties

A table of available properties and their usage can be found here

Methods

A table of available methods and their usage can be found here

Settings

Each button is assigned a default class and default content based on its respective filetype and corresponding css styles.

/* default class, content, and separator for each export type */

/* Excel Open XML spreadsheet (.xlsx) */
$.fn.tableExport.xlsx = {
    defaultClass: "xlsx",
    buttonContent: "Export to xlsx",
    mimeType: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    fileExtension: ".xlsx"
};

/* Excel Binary spreadsheet (.xls) */
$.fn.tableExport.xls = {
    defaultClass: "xls",
    buttonContent: "Export to xls",
    separator: "\t",
    mimeType: "application/vnd.ms-excel",
    fileExtension: ".xls"
};

/* Comma Separated Values (.csv) */
$.fn.tableExport.csv = {
    defaultClass: "csv",
    buttonContent: "Export to csv",
    separator: ",",
    mimeType: "application/csv",
    fileExtension: ".csv"
};

/* Plain Text (.txt) */
$.fn.tableExport.txt = {
    defaultClass: "txt",
    buttonContent: "Export to txt",
    separator: "  ",
    mimeType: "text/plain",
    fileExtension: ".txt"
};

Below are additional defaults to support the functionality of the plugin that.

/* default charset encoding (UTF-8) */
$.fn.tableExport.charset = "charset=utf-8";

/* default filename if "id" attribute is set and undefined */
$.fn.tableExport.defaultFilename = "myDownload";

/* default class to style buttons when not using bootstrap  */
$.fn.tableExport.defaultButton = "button-default";

/* bootstrap classes used to style and position the export buttons */
$.fn.tableExport.bootstrap = ["btn", "btn-default", "btn-toolbar"];

/* row delimeter used in all filetypes */
$.fn.tableExport.rowDel = "\r\n";

Browser Support

ChromeFirefoxIEOperaSafari *
Android--
iOS---
Mac OSX-
Windows

*only partial support for xls and xlsx: requires third-party dependency (Blob.js)

Live Demo

A live, interactive demo can be found on the TableExport webpage.

License

TableExport.js is licensed under the terms of the MIT License

:star: Credits

Special thanks the the following contributors:

Keywords

FAQs

Package last updated on 04 May 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc