Skip to content

Commit 31ad32b

Browse files
committed
v1.0.3 filename option for save-as dialog
1 parent c45275c commit 31ad32b

7 files changed

+23
-9
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@
2222
```javascript
2323
$("#yourHtmTable").table2excel({
2424
exclude: ".excludeThisClass",
25-
name: "Worksheet Name"
25+
name: "Worksheet Name",
26+
filename: "SomeFile" //do not include extension
2627
});
2728
```
2829

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jquery-table2excel",
3-
"version": "1.0.2",
3+
"version": "1.0.3",
44
"homepage": "https://github.com/jquery-table2excel/",
55
"authors": [
66
"rainabba <[email protected]>"

demo/index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
$(function() {
3939
$(".table2excel").table2excel({
4040
exclude: ".noExl",
41-
name: "Excel Document Name"
41+
name: "Excel Document Name",
42+
filename: "myFileName"
4243
});
4344
});
4445
</script>

dist/jquery.table2excel.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@
5858
e.tableRows.push(tempRows);
5959
});
6060

61+
6162
e.tableToExcel(e.tableRows, e.settings.name);
6263
},
6364

6465
tableToExcel: function (table, name) {
65-
var e = this, fullTemplate="", i;
66+
var e = this, fullTemplate="", i, link, a;
6667

6768
e.uri = "data:application/vnd.ms-excel;base64,";
6869
e.base64 = function (s) {
@@ -102,7 +103,12 @@
102103
}
103104
delete e.ctx.table;
104105

105-
window.location.href = e.uri + e.base64(e.format(fullTemplate, e.ctx));
106+
link = e.uri + e.base64(e.format(fullTemplate, e.ctx));
107+
a = document.createElement("a");
108+
a.download = ( e.settings.filename ? e.settings.filename : "table2excel") + ".xlsx";
109+
a.href = link;
110+
a.click();
111+
106112
}
107113
};
108114

dist/jquery.table2excel.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"url": "http://github.com/rainabba/jquery-table2excel.git"
99
},
1010
"homepage": "https://github.com/rainabba/jquery-table2excel/",
11-
"version": "1.0.2",
11+
"version": "1.0.3",
1212
"devDependencies": {
1313
"grunt": "~0.4.5",
1414
"grunt-cli": "~0.1.13",

src/jquery.table2excel.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@
5050
e.tableRows.push(tempRows);
5151
});
5252

53+
5354
e.tableToExcel(e.tableRows, e.settings.name);
5455
},
5556

5657
tableToExcel: function (table, name) {
57-
var e = this, fullTemplate="", i;
58+
var e = this, fullTemplate="", i, link, a;
5859

5960
e.uri = "data:application/vnd.ms-excel;base64,";
6061
e.base64 = function (s) {
@@ -94,7 +95,12 @@
9495
}
9596
delete e.ctx.table;
9697

97-
window.location.href = e.uri + e.base64(e.format(fullTemplate, e.ctx));
98+
link = e.uri + e.base64(e.format(fullTemplate, e.ctx));
99+
a = document.createElement("a");
100+
a.download = ( e.settings.filename ? e.settings.filename : "table2excel") + ".xlsx";
101+
a.href = link;
102+
a.click();
103+
98104
}
99105
};
100106

0 commit comments

Comments
 (0)