<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <script type="text/javascript"> function writeToExcel2() { var i, j, str, myTable = document.getElementById('GridView1'), rowCount = myTable.rows.length, excel = new ActiveXObject('Excel.Application');// Activates Excel excel.Workbooks.Add(); // Opens a new Workbook excel.Application.Visible = true; // Shows Excel on the screen for (i = 0; i < rowCount; i++) { for (j = 0; j < myTable.rows[i].cells.length; j++) { str = myTable.rows[i].cells[j].innerText; excel.ActiveSheet.Cells(i + 1, j + 1).Value = str; // Writes to the sheet } } return; } </script> </head> <body> <form id="form1" runat="server" style="text-align:center;"> <div > <h1><asp:Label ID="Label1" runat="server" Text="Label">EXPORTING GRIDVIEW</asp:Label></h1> </div> <div id="printme" align="center"> <asp:GridView ID="GridView1" runat="server"> </asp:GridView> </div> <br /> <input type="submit" onclick="writeToExcel2();" value="EXPORT TO EXCEL USING ACTIVEX" /> </form> </body> </html>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)