10
Questa è la funzione che uso per generare i miei file .xls di ExcelC'è un modo per impostare un contenuto sicuro su un file Excel generato da js?
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]; }) }
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))
}
})()
tableToExcel('table', 'Table Title')
E questo è l'errore che ottengo
hai controllato il problema che l'errore implica? estensione .xls e il tipo di contenuto corrisponde o hai impostato in modo errato? – Thorarins
è io o il codice creerà il file XLSX non XLS – Poof
@Proof: Il codice crea una miscela di 'HTML' e incorporato' XML' se '' La versione di '' 'è maggiore o uguale a 9' '. 'Excel' accetterà questa miscela come file' * .xls' e analizzerà la miscela per creare una cartella di lavoro da essa. Ma lancerà quell'avvertimento. Ci sono soluzioni 'JavaScript' in natura che possono realmente creare' XLS' e/o 'XLSX'. Cerca parole chiave: 'javascript create excel xls xlsx'. –