Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 139805

Javascript to export html from web page into excel template (xltx)

$
0
0

I want to use javascript to export html from my web page into a specific excel template (extension xltx). I found this code below which is working perfectly to export the html into a new workbook, however I have not been able to figure out how to modify this so that it will export it into an xltx template that I have created. I am new to coding, so I apologize if this is a dumb question. I searched, but have found no solution yet. Any help would be appreciated!

function clickEvent_Test() {

    var htmls = htmlHeaders + htmlString;
    var uri = 'data:application/vnd.openxmlformats-officedocument.spreadsheetml.template;base64,';
    var 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>';
    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];
        })
    };


    var ctx = {
        worksheet: 'AllData',
        table: htmls
    }


    var link = document.createElement("a");
    link.download = "TrackerExport.xls";
    link.href = uri + base64(format(template, ctx));
    link.click();
}

Viewing all articles
Browse latest Browse all 139805

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>