Всем доброго!
есть маленький пример, но как заставить чтоб в документе эксель появился и заголовок таблицы?
<input type="button" onclick="tableToExcel('testTable', 'W3C Example Table')" value="Export to Excel">
<label class='col-md-10'>
<h3>ТАБЛИЦА №1</h3>
</label>
<div class="col-md-12 tabl">
<table class="mytable" cellspacing="0" id="testTable" border="1">
<thead><tr><th>№</th><th>N ВАГОНА</th><th>НАЗН</th><th>ВЕС</th><th>ГРУЗ</th><th>ПОЛУЧ</th><th>ОПЕР</th><th>ДАТА</th><th>ВРЕМЯ</th><th>ИНДЕКС ПОЕЗДА</th></tr>
</thead><tr><td>1</td><td>77330025</td><td>72010</td><td>000</td><td>42103</td><td>00000</td><td>ИСКП</td><td>17 25</td><td>08 10 28</td><td>+ + </td></tr>
<tr><td>2</td><td>77330165</td><td>72010</td><td>000</td><td>42103</td><td>00000</td><td>ИСКП</td><td>17 25</td><td>08 10 28</td><td>+ + </td></tr>
<tr><td>11</td><td>87778072</td><td>72010</td><td>000</td><td>00000</td><td>00000</td><td>ИСКП</td><td>17 28</td><td>08 15 59</td><td>+ + </td></tr>
<tr><td>12</td><td>87778080</td><td>72010</td><td>000</td><td>00000</td><td>00000</td><td>ИСКП</td><td>17 28</td><td>08 15 59</td><td>+ + </td></tr>
<tr><td>13</td><td>87781456</td><td>72010</td><td>000</td><td>42103</td><td>00000</td><td>ИСКП</td><td>17 30</td><td>08 11 00</td><td>+ + </td></tr>
<tr><td>25</td><td>94217700</td><td>00000</td><td>000</td><td>00000</td><td>00000</td><td>ПРИБ</td><td>17 30</td><td>08 10 57</td><td>69800+335+ 72000</td></tr>
</table>
<br/></div>
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]--><meta http-equiv="content-type" content="text/plain; charset=UTF-8"/></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];
})
}
return function(table, name) {
if (!table.nodeType) table = document.getElementById(table)
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML}
window.location.href = uri + base64(format(template, ctx))
}
})()
вот линк на
jsfiddle