Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
I tried the below code working fine in Chrome but the problem is the downloaded excel sheet not having cellborders

C#
var currentID = ($(this).attr('id'));
                //getting values of current time for generating the file name
                var dt = new Date();
                var day = dt.getDate();
                var month = dt.getMonth() + 1;
                var year = dt.getFullYear();
                var hour = dt.getHours();
                var mins = dt.getMinutes();
                var postfix = day + "." + month + "." + year + "_" + hour + "." + mins;
                //creating a temporary HTML link element (they support setting file names)
                var a = document.createElement('a');
                //getting data from our div that contains the HTML table
                var data_type = 'data:application/vnd.ms-excel';
                var table_div = null;
                if (currentID == "aRenewal_Queue") {
                    table_div = document.getElementById('divRenewal_Queue');
                    a.download = 'RenewalQuotes' + postfix + '.xls';
                }

                else if (currentID == "aRenewal_Bind") {
                    table_div = document.getElementById('divRenewal_Bind');
                    a.download = 'RenewalBinds' + postfix + '.xls';
                }
                else
                {
                    table_div = document.getElementById('divLobWise_Queue');
                    a.download = 'LOBWISELEADS' + postfix + '.xls';
                }
                   

                var table_html = table_div.outerHTML.replace(/ /g, '%20');
                a.href = data_type + ', ' + table_html;
                //setting the file name
                //a.download = 'RenewalQuotes' + postfix + '.xls';
                //triggering the function
                a.click();
                //just in case, prevent default behaviour
                e.preventDefault();


Please help to get borders in Excel

Thanks in advance.
KArtik

What I have tried:

C#
var currentID = ($(this).attr('id'));
                //getting values of current time for generating the file name
                var dt = new Date();
                var day = dt.getDate();
                var month = dt.getMonth() + 1;
                var year = dt.getFullYear();
                var hour = dt.getHours();
                var mins = dt.getMinutes();
                var postfix = day + "." + month + "." + year + "_" + hour + "." + mins;
                //creating a temporary HTML link element (they support setting file names)
                var a = document.createElement('a');
                //getting data from our div that contains the HTML table
                var data_type = 'data:application/vnd.ms-excel';
                var table_div = null;
                if (currentID == "aRenewal_Queue") {
                    table_div = document.getElementById('divRenewal_Queue');
                    a.download = 'RenewalQuotes' + postfix + '.xls';
                }

                else if (currentID == "aRenewal_Bind") {
                    table_div = document.getElementById('divRenewal_Bind');
                    a.download = 'RenewalBinds' + postfix + '.xls';
                }
                else
                {
                    table_div = document.getElementById('divLobWise_Queue');
                    a.download = 'LOBWISELEADS' + postfix + '.xls';
                }
                   

                var table_html = table_div.outerHTML.replace(/ /g, '%20');
                a.href = data_type + ', ' + table_html;
                //setting the file name
                //a.download = 'RenewalQuotes' + postfix + '.xls';
                //triggering the function
                a.click();
                //just in case, prevent default behaviour
                e.preventDefault();
Posted
Updated 3-May-16 1:55am
v2
Comments
Kornfeld Eliyahu Peter 2-May-16 5:13am    
'not working' is a very poor definition of problem...
Check for errors or warnings...Use the built in debugger to see where it goes wrong...Give details...

1 solution

AFAIK download [^] attribute is not supported in IE
You shall try this Export HTML Table Data to Excel Using JavaScript[^]
 
Share this answer
 

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