Skip to content
This repository has been archived by the owner on Jul 25, 2021. It is now read-only.

Commit

Permalink
v4.0.4 - add method to retrieve ArrayBuffer bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
clarketm committed May 23, 2017
1 parent 4100375 commit 48edb3c
Show file tree
Hide file tree
Showing 13 changed files with 81 additions and 46 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tableexport.js",
"version": "4.0.2",
"version": "4.0.4",
"authors": [
"clarketm <[email protected]>"
],
Expand Down
2 changes: 1 addition & 1 deletion dist/css/tableexport.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* TableExport.js v4.0.2 (https://www.travismclarke.com)
* TableExport.js v4.0.4 (https://www.travismclarke.com)
* Copyright 2017 Travis Clarke
* Licensed under the MIT license
*/
Expand Down
2 changes: 1 addition & 1 deletion dist/css/tableexport.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 23 additions & 18 deletions dist/js/tableexport.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* TableExport.js v4.0.2 (https://www.travismclarke.com)
* TableExport.js v4.0.4 (https://www.travismclarke.com)
* Copyright 2017 Travis Clarke
* Licensed under the MIT license
*/
Expand Down Expand Up @@ -124,7 +124,7 @@
* Version.
* @memberof TableExport.prototype
*/
version: '4.0.2',
version: '4.0.4',
/**
* Default library options.
* @memberof TableExport.prototype
Expand Down Expand Up @@ -694,22 +694,7 @@
* @param extension {String} file extension
*/
export2file: function (data, mime, name, extension) {
if (XLSX && !isMobile && extension.substr(0, 4) === '.xls') {
var wb = new this.Workbook(),
ws = this.createSheet(data),
bookType = extension.substr(1) === _type.xls ? _type.biff2 : _type.xlsx;

wb.SheetNames.push(name);
wb.Sheets[name] = ws;
var wopts = {
bookType: bookType,
bookSST: false,
type: 'binary'
},
wbout = XLSX.write(wb, wopts);

data = this.string2ArrayBuffer(wbout);
}
data = this.getBinaryData(data, extension, name);

if (isMobile) {
var dataURI = 'data:' + mime + ';' + this.charset + ',' + data;
Expand All @@ -728,6 +713,26 @@
document.body.appendChild(link);
link.click();
},
getBinaryData: function (data, extension, name) {
if (XLSX && !isMobile && extension.substr(0, 4) === '.xls') {
var wb = new this.Workbook(),
ws = this.createSheet(data),
bookType = extension.substr(1) === _type.xls ? _type.biff2 : _type.xlsx;

name = name || '';
wb.SheetNames.push(name);
wb.Sheets[name] = ws;
var wopts = {
bookType: bookType,
bookSST: false,
type: 'binary'
},
wbout = XLSX.write(wb, wopts);

data = this.string2ArrayBuffer(wbout);
}
return data;
},
/**
* Updates the library instance with new/updated options
* @param options {Object} TableExport configuration options
Expand Down
4 changes: 2 additions & 2 deletions dist/js/tableexport.min.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions examples/examples.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ code {
.info.code {
font-size: 80%;
}
.info.code.nested {
width: auto;
}
.target {
background: yellow;
font-weight: bold;
Expand Down
4 changes: 4 additions & 0 deletions examples/examples.less
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ code {
font-size: 80%;
}

.info.code.nested {
width: auto;
}

.target {
background: yellow;
font-weight: bold;
Expand Down
18 changes: 18 additions & 0 deletions examples/exportButtons.html
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ <h1>ExportButtons
</pre>
</div>

<br>

<div class="info">Additionally, the raw binary data (and byte length) can be retrieved using the <code>getBinaryData</code> prototype method.
<div class="info code nested">
<pre>
// get raw binary data (i.e. filesize)
var bytes = TableExport.prototype.getBinaryData(exportData.data, exportData.fileExtension);
var byteLength = bytes.byteLength;
</pre>
</div>
</div>


</main>

<script type="text/javascript" src="../bower_components/jquery/dist/jquery.min.js"></script>
Expand All @@ -126,6 +139,11 @@ <h1>ExportButtons
// // "id" of selector // format
var exportData = instance.getExportData()['export-buttons-table']['xls'];

// get raw binary data (i.e. filesize)
var bytes = TableExport.prototype.getBinaryData(exportData.data, exportData.fileExtension).byteLength;

console.log('filesize:', bytes + 'B');

var XLSbutton = document.getElementById('customXLSButton');
XLSbutton.addEventListener('click', function (e) {
// // data // mime // name // extension
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tableexport",
"version": "4.0.2",
"version": "4.0.4",
"authors": [
"clarketm <[email protected]>"
],
Expand Down
2 changes: 1 addition & 1 deletion src/stable/css/tableexport.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* TableExport.js v4.0.2 (https://www.travismclarke.com)
* TableExport.js v4.0.4 (https://www.travismclarke.com)
* Copyright 2017 Travis Clarke
* Licensed under the MIT license
*/
Expand Down
2 changes: 1 addition & 1 deletion src/stable/css/tableexport.min.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 23 additions & 18 deletions src/stable/js/tableexport.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*!
* TableExport.js v4.0.2 (https://www.travismclarke.com)
* TableExport.js v4.0.4 (https://www.travismclarke.com)
* Copyright 2017 Travis Clarke
* Licensed under the MIT license
*/
Expand Down Expand Up @@ -124,7 +124,7 @@
* Version.
* @memberof TableExport.prototype
*/
version: '4.0.2',
version: '4.0.4',
/**
* Default library options.
* @memberof TableExport.prototype
Expand Down Expand Up @@ -694,22 +694,7 @@
* @param extension {String} file extension
*/
export2file: function (data, mime, name, extension) {
if (XLSX && !isMobile && extension.substr(0, 4) === '.xls') {
var wb = new this.Workbook(),
ws = this.createSheet(data),
bookType = extension.substr(1) === _type.xls ? _type.biff2 : _type.xlsx;

wb.SheetNames.push(name);
wb.Sheets[name] = ws;
var wopts = {
bookType: bookType,
bookSST: false,
type: 'binary'
},
wbout = XLSX.write(wb, wopts);

data = this.string2ArrayBuffer(wbout);
}
data = this.getBinaryData(data, extension, name);

if (isMobile) {
var dataURI = 'data:' + mime + ';' + this.charset + ',' + data;
Expand All @@ -728,6 +713,26 @@
document.body.appendChild(link);
link.click();
},
getBinaryData: function (data, extension, name) {
if (XLSX && !isMobile && extension.substr(0, 4) === '.xls') {
var wb = new this.Workbook(),
ws = this.createSheet(data),
bookType = extension.substr(1) === _type.xls ? _type.biff2 : _type.xlsx;

name = name || '';
wb.SheetNames.push(name);
wb.Sheets[name] = ws;
var wopts = {
bookType: bookType,
bookSST: false,
type: 'binary'
},
wbout = XLSX.write(wb, wopts);

data = this.string2ArrayBuffer(wbout);
}
return data;
},
/**
* Updates the library instance with new/updated options
* @param options {Object} TableExport configuration options
Expand Down
Loading

0 comments on commit 48edb3c

Please sign in to comment.