var tableToExcel = function() {
var uri = 'data:application/vnd.ms-excel;base64,',
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>',
base64 = function(s) {
return window.btoa(unescape(encodeURIComponent(s)))
},
format = function(s, c) {
return s.replace(/{(\w+)}/g,
function(m, p) {
return c[p];
})
};
var tableHTML="<tbody>";
tableHTML+="<tr>";
tableHTML+="<td>";
tableHTML+='p41.value';
tableHTML+="</td>";
tableHTML+="<td>";
tableHTML+='p42.value';
tableHTML+="</td>";
tableHTML+="<td>";
tableHTML+='p43.value';
tableHTML+="</td>";
tableHTML+="<td>";
tableHTML+='p40.value';
tableHTML+="</td>";
tableHTML+="<td>";
tableHTML+='p39.value';
tableHTML+="</td>";
tableHTML+="<td>";
tableHTML+='p1.value';
tableHTML+="</td>";
tableHTML+="</tr>";
tableHTML+="</tbody>";
return function(html, name) {
var ctx = {
worksheet: name || 'Worksheet',
table: html
};
window.location.href = uri + base64(format(template, ctx))
}(tableHTML, "???");
};
tableToExcel();
1, for the Script, whether the document can be output directly to excel in Script code inside.
2, Script code is based on ECMAScript, which I have used in the script code embedded object browser window, such as window.location.href, then the error: "window" not defined, would like to ask why did not add to the browser embedded support objects
3, if Script excel file can not be output through the code, so if there are other ways to generate excel file by writing code
Is there a software system which can be called directly related to the function or function object and then output file?
Thanks
Attachment: download link