table-exporter
v0.0.12
Published
Export HTML Table (Table Tag, Table CSS) to a file (JSON, CSV, etc.)
Downloads
3
Maintainers
Readme
table-exporter
Export HTML Table (Table Tag, Table CSS) to a file (JSON, CSV, etc.)
Usage
node bin/export_table table.html
Examples
var exporter = require('table-exporter');
/**
* exporter = function (html, tableSelector, targetSelector, callback)
*/
var html = `<html>
<body>
<table>
<tr>
<th>Column One</th>
<th>Column Two</th>
<th>Column Three</th>
</tr>
<tr>
<td>Row 1 Col 1</td>
<td>Row 1 Col 2</td>
<td>Row 1 Col 3 </td>
</tr>
<tr>
<td>Row 2 Col 1</td>
<td>Row 2 Col 2</td>
<td>Row 2 Col 3</td>
</tr>
<tr>
<td>Row 3 Col 1</td>
<td>Row 3 Col 2</td>
<td>Row 3 Col 3</td>
</tr>
</table>
</body>
</html>`
var tables = exporter.export(html);
// output is an array of table that are found
// for example
// tables === [{"headers":["Column One","Column Two","Column Three"],"rows":[["Row 1 Col 1","Row 1 Col 2","Row 1 Col 3 "],["Row 2 Col 1","Row 2 Col 2","Row 2 Col 3"],["Row 3 Col 1","Row 3 Col 2","Row 3 Col 3"]]}]
Use in a brower
Install Browserify
npm install --global browserify
Produce Table Exporter Javascript Bundle
browserify web.js -o web/te.js
<!DOCTYPE>
<html>
<head>
<script src="../te.js"></script>
</head>
<body>
</body>
</html>