Export HTML Table to Excel with JS

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    
    <script Language="javascript">
        function TableToExcel() {
            var strCopy = document.getElementById("detailsTable").innerHTML;
            window.clipboardData.setData("Text", strCopy);
            var objExcel = new ActiveXObject("Excel.Application");
            objExcel.visible = true;

            var objWorkbook = objExcel.Workbooks.Add;
            var objWorksheet = objWorkbook.Worksheets(1);
            objWorksheet.Paste;
        }

        function exportToExcel() {
            var oExcel = new ActiveXObject("Excel.Application");
            var oBook = oExcel.Workbooks.Add;
            var oSheet = oBook.Worksheets(1);
            for (var y = 0; y < detailsTable.rows.length; y++)
            // detailsTable is the table where the content to be exported is
            {
                for (var x = 0; x < detailsTable.rows(y).cells.length; x++) {
                    oSheet.Cells(y + 1, x + 1) = detailsTable.rows(y).cells(x).innerText;
                }
            }
            oExcel.Visible = true;
            oExcel.UserControl = true;
        }
    </script>
    <title></title>
</head>
<body>
    <table id="detailsTable" border="1">
      <tr>
        <th>Month</th>
        <th>Savings</th>
      </tr>
      <tr>
        <td>January</td>
        <td>$100</td>
      </tr>
    </table>
    </span>
    <input id="clickExcel" type="button" value="button" onclick="javascript:TableToExcel()"/>
    <a href="javascript:exportToExcel();">Export to Excel</a><br/>
</body>
</html>