Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
JavaScript
<script type="text/javascript">
        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))
            }
        })()
    </script>


using this code exproting html table to excel. My question is can i export html table to specified excel sheet template which i have already made.
Posted
Comments
W Balboos, GHB 15-Apr-15 7:48am    
When I do such stuff I'll use php and an OBDC connection to the Excel driver (must be on same server as php). You can then handle the output much like SQL inserts. There are some restrictions (you can't delete a row, for example) but it can be a lot of fun.

1 solution

Hi,

You can not export html table by javascript or jquery if you have browser IE8 or below version.

if you are using other browser and code not working then check then security issue.
 
Share this answer
 
v3
Comments
Muhamad Faizan Khan 16-Apr-15 0:34am    
i am doing export. it working fine. Please read question carefully
anil pathak 16-Apr-15 2:32am    
i read your question, but can you tried on IE 8 or below. because "data:application/vnd.ms-excel" is not supported by same browser

ok, let it be. if you are able export then can make a html template and replace your data by ajax call from server in template by loop in object in jquery or javascript.

And you can try what you doing..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900