table2csv live example

Star Fork Issue Fork me on GitHub

A simple jQuery plugin to convert HTML tables to CSV. It allows you to download or display the content of a regular HTML table as a CSV file.

It is useful if you want to quickly build a downloadable report from a web based tool.

Check out the repository or the npm page of the package

I wrote this plugin in my spare time. Feel free to file an issue or create a pull request if you think I missed something!

Installation

You can install this plugin from npm

    
$ npm install table2csv
    

Usage

Import jQuery and this script

    
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<script src="/path/to/table2csv.min.js"></script>
    

then invoke the table2csv() function on the jQuery object of the table

$("table").first().table2csv(); // default action is 'download'

The plugin currently convert just one table at a time and must be called directly on the table you want to convert.

table2csv() accepts 2 arguments, both optional: action and options. Click here for full documentation or just try the live example below.

Interactive example

Below an example table and the corresponding HTML code

Company Contact Country
Alfreds Futterkiste Maria Anders Germany
Centro comercial Moctezuma Francisco Chang Mexico
Ernst Handel Roland Mendel Austria
Island Trading Helen Bennett UK
Laughing Bacchus Winecellars Yoshi Tannamuri Canada
Magazzini Alimentari Riuniti Giovanni Rovelli Italy
Seeverkehr Johannes Gutenberg München
        
    

Change values on the left to see the corresponding code, then press the button to see that code in action!

Action
Options






            
        

Press the button below to execute the code snippet above

#output