Skip to content
This repository was archived by the owner on Sep 6, 2022. It is now read-only.

Commit 3bbc8ff

Browse files
committed
Merge pull request rainabba#32 from iBrotNano/feature/set-sheetname
rainabba#28 how to change excel sheet name
2 parents 06b783d + 77dd3d8 commit 3bbc8ff

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/jquery.table2excel.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
var e = this;
2727

2828
e.template = {
29-
head: "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets>",
29+
head: "<html xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns=\"http://www.w3.org/TR/REC-html40\"><meta http-equiv=\"content-type\" content=\"application/vnd.ms-excel; charset=UTF-8\"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets>",
3030
sheet: {
3131
head: "<x:ExcelWorksheet><x:Name>",
3232
tail: "</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet>"
@@ -50,10 +50,10 @@
5050
e.tableRows.push(tempRows);
5151
});
5252

53-
e.tableToExcel(e.tableRows, e.settings.name);
53+
e.tableToExcel(e.tableRows, e.settings.name, e.settings.sheetName);
5454
},
5555

56-
tableToExcel: function (table, name) {
56+
tableToExcel: function (table, name, sheetName) {
5757
var e = this, fullTemplate="", i, link, a;
5858

5959
e.uri = "data:application/vnd.ms-excel;base64,";
@@ -65,17 +65,21 @@
6565
return c[p];
6666
});
6767
};
68+
69+
sheetName = typeof sheetName == "undefined" ? "Sheet" : sheetName;
70+
6871
e.ctx = {
6972
worksheet: name || "Worksheet",
70-
table: table
73+
table: table,
74+
sheetName: sheetName,
7175
};
7276

7377
fullTemplate= e.template.head;
7478

7579
if ( $.isArray(table) ) {
7680
for (i in table) {
77-
//fullTemplate += e.template.sheet.head + "{worksheet" + i + "}" + e.template.sheet.tail;
78-
fullTemplate += e.template.sheet.head + "Table" + i + "" + e.template.sheet.tail;
81+
//fullTemplate += e.template.sheet.head + "{worksheet" + i + "}" + e.template.sheet.tail;
82+
fullTemplate += e.template.sheet.head + sheetName + i + e.template.sheet.tail;
7983
}
8084
}
8185

0 commit comments

Comments
 (0)