I'm using TableToExcel, it is working fine on Windows Excel, but when exporting it and opening it on Excel:Mac 2011. here's my code in TableToExcel:
var tableToExcel = (function() {
var uri = 'data:application/vnd.ms-excel;base64,';
var template = '<html ' +
'xmlns="urn:schemas-microsoft-com:office:office" ' +
'xmlns:o="urn:schemas-microsoft-com:office:office"' +
'xmlns:x="urn:schemas-microsoft-com:office:excel" ' +
'xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" ' +
'xmlns:html="https://www.w3.org/TR/html40/" >' +
'<head>' +
'<meta http-equiv="content-type" content="text/plain; charset=UTF-8"/>'+
'<!--[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>' +
'<font face="Arial" size="12">' +
'<table>{table}</table>' +
'</font>' +
'</body>' +
'</html>';
var base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))); };
var format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { return c[p]; }); };
return function(table, name, filename) {
if (!table.nodeType) table = document.getElementById(table);
var ctx = {worksheet: name || 'Worksheet', table: table.innerHTML};
var link = document.createElement("A");
link.href = uri + base64(format(template, ctx));
var loc = window.location.pathname;
var dir = loc.substring(0, loc.lastIndexOf('/'));
link.download = filename || 'Workbook.xls';
link.target = '_blank';
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
};
})();
I've tried changing background-color or background, adding <x:Panes></x:Panes>, or <x:Print><x:Gridlines /></x:Print> changing MIME, removing all content of table, still the gridlines won't show.
I thought of using Datatables for Excel exporting, but It is difficult to manually change the formats (e.g. font style, size, row height, etc.) compared to what I have now
EDIT:
Been searching for a while with different libraries using JQuery. Still can't find a better solution to my problem. Might try the DataTables exporting functions and just modify it.
EDIT2:
I have no luck on Datatables, I got back on tableToExcel.js because what I really want to achieve is to apply formats on different rows,cell,column,etc.
from Export HTML TableToExcel not showing gridlines in Excel
No comments:
Post a Comment