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

Commit

Permalink
support for customizing worksheet name, #163
Browse files Browse the repository at this point in the history
  • Loading branch information
clarketm committed Dec 19, 2018
1 parent 4323136 commit a46a2dd
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 38 deletions.
33 changes: 15 additions & 18 deletions dist/js/tableexport.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,8 @@
context.rows = settings.headers ? _nodesArray(el.querySelectorAll("thead > tr")).concat(context.rows) : context.rows;
context.rows = settings.footers ? context.rows.concat(_nodesArray(el.querySelectorAll("tfoot > tr"))) : context.rows;
context.thAdj = settings.headers ? el.querySelectorAll("thead > tr").length : 0;
context.filename =
settings.filename === "id"
? el.getAttribute("id")
? el.getAttribute("id")
: self.defaultFilename
: settings.filename
? settings.filename
: self.defaultFilename;
context.filename = settings.filename === "id" ? el.getAttribute("id") || self.defaultFilename : settings.filename || self.defaultFilename;
context.sheetname = settings.sheetname === "id" ? el.getAttribute("id") || self.defaultFilename : settings.sheetname || self.defaultFilename;
context.uuid = _uuid(el);

/**
Expand Down Expand Up @@ -164,7 +158,8 @@
ignoreRows: null, // (Number, Number[]), row indices to exclude from the exported file(s) (default: null)
ignoreCols: null, // (Number, Number[]), column indices to exclude from the exported file(s) (default: null)
trimWhitespace: true, // (Boolean), remove all leading/trailing newlines, spaces, and tabs from cell text in the exported file(s) (default: false)
RTL: false // (Boolean), set direction of the worksheet to right-to-left (default: false)
RTL: false, // (Boolean), set direction of the worksheet to right-to-left (default: false)
sheetname: "id" // (id, String), sheet name for the exported spreadsheet, (default: 'id')
},
/**
* Constants
Expand Down Expand Up @@ -398,7 +393,8 @@
mimeType: format.mimeType,
fileExtension: format.fileExtension,
merges: rcMap.merges,
RTL: settings.RTL
RTL: settings.RTL,
sheetname: settings.sheetname
});

var hashKey = _hashCode({ uuid: context.uuid, type: key });
Expand Down Expand Up @@ -542,8 +538,9 @@
mimeType = object.mimeType,
fileExtension = object.fileExtension,
merges = object.merges,
RTL = object.RTL;
this.export2file(data, mimeType, filename, fileExtension, merges, RTL);
RTL = object.RTL,
sheetname = object.sheetname;
this.export2file(data, mimeType, filename, fileExtension, merges, RTL, sheetname);
},
/**
* Excel Workbook constructor
Expand Down Expand Up @@ -577,9 +574,9 @@
* @param merges {Object[]}
* @param RTL {Boolean}
*/
export2file: function(data, mime, name, extension, merges, RTL) {
export2file: function(data, mime, name, extension, merges, RTL, sheetname) {
var format = extension.slice(1);
data = this.getRawData(data, extension, name, merges, RTL);
data = this.getRawData(data, extension, name, merges, RTL, sheetname);

if (_isMobile && (format === _FORMAT.CSV || format === _FORMAT.TXT)) {
var dataURI = "data:" + mime + ";" + this.charset + "," + data;
Expand All @@ -605,17 +602,17 @@
return key;
}
},
getRawData: function(data, extension, name, merges, RTL) {
getRawData: function(data, extension, name, merges, RTL, sheetname) {
var key = extension.substring(1);

if (_isEnhanced(key)) {
var wb = new this.Workbook(),
ws = this.createSheet(data, merges),
bookType = this.getBookType(key);

name = name || "";
wb.SheetNames.push(name);
wb.Sheets[name] = ws;
sheetname = sheetname || "";
wb.SheetNames.push(sheetname);
wb.Sheets[sheetname] = ws;
wb.Workbook.Views[0] = { RTL: RTL };
var wopts = {
bookType: bookType,
Expand Down
Loading

0 comments on commit a46a2dd

Please sign in to comment.