tableexport
Version:
The simple, easy-to-implement library to export HTML tables to xlsx, xls, csv, and txt files
159 lines (142 loc) • 5.39 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Sheetname</title>
<link href="../dist/css/tableexport.min.css" rel="stylesheet">
<link href="./examples.css" rel="stylesheet">
</head>
<body>
<noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-TL44T9" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<a id="example-link" href="./"> << Examples</a>
<iframe src="./defaults.html" frameborder="0" width="100%" scrolling="no" onload="this.height=screen.height/2.5;"></iframe>
<main>
<h1>Sheetname<span class="small">- string</span>
<code class="small">sheetname: 'super-worksheet'</code>
<span class="note"> ... OR any <code>string</code> besides <code>"id"</code></span>
</h1>
<table id="sheetname-table-1">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Age</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>Thor Walton</td>
<td>Regional Director</td>
<td>45</td>
<td>$98,540</td>
</tr>
<tr>
<td>Travis Clarke</td>
<td>Software Engineer</td>
<td>30</td>
<td>$275,000</td>
</tr>
<tr>
<td>Suki Burks</td>
<td>Office Manager</td>
<td>22</td>
<td>$67,670</td>
</tr>
</tbody>
<tfoot>
<tr>
<td class="disabled"></td>
<td class="disabled"></td>
<td class="disabled"></td>
<th>$441,210</th>
</tr>
</tfoot>
</table>
<p class="info">export the table to <code>.xlsx</code> and look at the sheetname of the downloaded file. Compared to the export from the <b>defaults</b> table above, you will notice that, <code>sheetname: 'super-worksheet'</code><i>creates a worksheet with the same name as the provided string </i>(<b>super-worksheet</b>)<i> instead of the table element's</i> <code>id</code>.</p>
</main>
<br>
<main>
<h1>Sheetname<span class="small">- falsey</span>
<code class="small">sheetname: false</code>
<span class="note"> ... OR any <code>falsey: false|null|undefined|""</code> value</span>
</h1>
<table id="sheetname-table-2">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Age</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
<tr>
<td>Thor Walton</td>
<td>Regional Director</td>
<td>45</td>
<td>$98,540</td>
</tr>
<tr>
<td>Travis Clarke</td>
<td>Software Engineer</td>
<td>30</td>
<td>$275,000</td>
</tr>
<tr>
<td>Suki Burks</td>
<td>Office Manager</td>
<td>22</td>
<td>$67,670</td>
</tr>
</tbody>
<tfoot>
<tr>
<td class="disabled"></td>
<td class="disabled"></td>
<td class="disabled"></td>
<th>$441,210</th>
</tr>
</tfoot>
</table>
<p class="info">
export the table to <code>.xlsx</code> and look at the sheetname of the downloaded file. Compared to the export from the <b>defaults</b> table above, you will notice that, <code>sheetname: false</code><i> uses a <b>fallback</b> value for the sheetname; the fallback (or default) can be configured with the </i>(<code>defaultSheetname</code> prototype property).
</p>
<p>
<b>NOTE:</b> <code>defaultSheetname</code> is also used for <code>sheetname: 'id'</code> if the export <i>table</i> element does <b>NOT</b> have an <code>id</code> attribute.
</p>
<br>
</main>
<script type="text/javascript" src="../bower_components/jquery/dist/jquery.min.js"></script>
<script type="text/javascript" src="../bower_components/js-xlsx/dist/xlsx.core.min.js"></script>
<script type="text/javascript" src="../bower_components/blobjs/Blob.min.js"></script>
<script type="text/javascript" src="../bower_components/file-saverjs/FileSaver.min.js"></script>
<script type="text/javascript" src="../dist/js/tableexport.min.js"></script>
<script type="text/javascript" src="../assets/js/analytics.js"></script>
<script>
// Default sheetname if `sheetname: false|null|undefined|""`
TableExport.prototype.defaultSheetname = 'fallback-name';
// **** jQuery **************************
// $.fn.tableExport.defaultSheetname = 'fallback-name';
// **************************************
var SheetnameTable1 = document.getElementById('sheetname-table-1');
new TableExport(SheetnameTable1, {
sheetname: 'super-worksheet'
});
// **** jQuery **************************
// $(SheetnameTable1).tableExport({
// sheetname: 'super-worksheet'
// });
// **************************************
var SheetnameTable2 = document.getElementById('sheetname-table-2');
new TableExport(SheetnameTable2, {
sheetname: false // OR null OR undefined OR ""
});
// **** jQuery **************************
// $(SheetnameTable2).tableExport({
// sheetname: null
// });
// **************************************
</script>
</body>
</html>