|
29 | 29 |
|
30 | 30 | Plugin.prototype = {
|
31 | 31 | init: function () {
|
32 |
| - this.template = "<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><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>"; |
33 |
| - this.tableRows = ""; |
| 32 | + var e = this; |
| 33 | + e.template = "<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>"; |
| 34 | + e.template += "<x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions>"; |
| 35 | + e.template += "<x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>"; |
| 36 | + e.tableRows = ""; |
34 | 37 |
|
35 | 38 | // get contents of table except for exclude
|
36 |
| - $(this.element).find("tr").not(this.settings.exclude).each(function (i,o) { |
37 |
| - this.tableRows += "<tr>" + $(o).html() + "</tr>"; |
| 39 | + $(e.element).find("tr").not(this.settings.exclude).each(function (i,o) { |
| 40 | + e.tableRows += "<tr>" + $(o).html() + "</tr>"; |
38 | 41 | });
|
39 | 42 | this.tableToExcel(this.tableRows, this.settings.name);
|
40 | 43 | },
|
41 | 44 | tableToExcel: function (table, name) {
|
42 |
| - this.uri = "data:application/vnd.ms-excel;base64,"; |
43 |
| - this.base64 = function (s) { |
| 45 | + var e = this; |
| 46 | + e.uri = "data:application/vnd.ms-excel;base64,"; |
| 47 | + e.base64 = function (s) { |
44 | 48 | return window.btoa(unescape(encodeURIComponent(s)));
|
45 | 49 | };
|
46 |
| - this.format = function (s, c) { |
| 50 | + e.format = function (s, c) { |
47 | 51 | return s.replace(/{(\w+)}/g, function (m, p) {
|
48 | 52 | return c[p];
|
49 | 53 | });
|
50 | 54 | };
|
51 |
| - this.ctx = { |
| 55 | + e.ctx = { |
52 | 56 | worksheet: name || "Worksheet",
|
53 | 57 | table: table
|
54 | 58 | };
|
55 |
| - window.location.href = this.uri + this.base64(this.format(this.template, this.ctx)); |
| 59 | + window.location.href = e.uri + e.base64(e.format(e.template, e.ctx)); |
56 | 60 | }
|
57 | 61 | };
|
58 | 62 |
|
|
0 commit comments