function removeAllTooltips (node) { const tooltips = node.querySelectorAll('.tooltip'); [].forEach.call(tooltips, tooltip => { if (tooltip.parentNode) { tooltip.parentNode.removeChild(tooltip); } }); } function buildTableHTML (title, subtitle, footnote) { const titleHTML = `
${title}
`; const subtitleHTML = `${subtitle}
`; const footnoteHTML = `Note:${footnote}
`; const dataTableClone = document.querySelector('.data-table').cloneNode(true); removeAllTooltips(dataTableClone); const tableHTML = ` ${titleHTML.length > 0 ? titleHTML : ''} ${subtitleHTML.length > 0 ? subtitleHTML : ''} ${footnoteHTML.length > 0 ? footnoteHTML : ''} ${dataTableClone.outerHTML} `.split('>.<') .join('><') .split('>*<') .join('><'); return tableHTML; } function downloadXLS (html) { const filename = 'analysis.xls'; // IE/Edge if (window.navigator.msSaveOrOpenBlob) { const blobObject = new Blob([html]); return window.navigator.msSaveOrOpenBlob(blobObject, filename); } const dataURI = generateDataURI(html); const link = window.document.createElement('a'); link.href = dataURI; link.download = filename; document.body.appendChild(link); link.click(); document.body.removeChild(link); return true; } function generateDataURI (html) { const dataType = 'data:application/vnd.ms-excel;base64,'; const data = window.btoa(unescape(encodeURIComponent(html))); return `${dataType}${data}`; } export function exportXLS (title, subtitle, footnote) { // original was removing icon when starting export, disable and some spinner instead, shouldn't take enough time to warrant either..? const table = buildTableHTML(title, subtitle, footnote); downloadXLS(table); }