How to download a excel file from html using javascript ?

Table :

<table id=”mytable”>
{…}
</table>

Button :

<a download=”file.xls” href=”#” class=”btn-print” data-name=”#{mytable}”>
Download Excel File </a>

JavaScript :

<script>
    $('.btn-print').on('click', function() {
        var name = $(this).attr('data-name');
        return ExcellentExport.excel(this, 'mytable', 'title');
    });
</script>

ExcellentExport :

Download the ExcellentExport and add the files in your project.

https://github.com/jmaister/excellentexport

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s