Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 522
  • Last Modified:

Export GridView Data to Excel

Dear All Experts,

I need to export Gridview Data to excel by JavaScript code with supporting Arabic language

in ASP.net
0
Asrar Azmi
Asked:
Asrar Azmi
1 Solution
 
Kalpesh ChhatralaSoftware ConsultantCommented:
you can start with below code. you need to modify as per your requirement.

  function XlsExport()
 {
        try {
            var i;
            var j;
            var mycell;
            var tableID = "tblGridView";

            var objXLS = new ActiveXObject("Excel.Application");
            var objWB = objXLS.Workbooks.Add();
            var objWS = objWB.ActiveSheet;

            for (i = 0; i < document.getElementById('<%= tblAuditReport.ClientID %>').rows.length; i++) {
                for (j = 0; j < document.getElementById('<%= tblAuditReport.ClientID %>').rows(i).cells.length; j++) {
                    mycell = document.getElementById('<%= tblAuditReport.ClientID %>').rows(i).cells(j);
                    objWS.Cells(i + 1, j + 1).Value = mycell.innerText;
                }
            }

            //objWS.Range("A1", "L1").Font.Bold = true;

            objWS.Range("A1", "Z1").EntireColumn.AutoFit();

            objXL.Visible = true;

        }
        catch (err)
       {

       }

    }

Open in new window

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now