1

The below input is not calling JavaScript function TableToexcel

<html>

<body>


 <input type="button" value="Export to Excel" onclick="TableToExcel('tbldataresult') "/>

 <script type="text/javascript" language="javascript">

                 function TableToExcel(tableid) {

                     debugger;

                var id = $('[id$="' + tableid + '"]');
                var strCopy = $('<div></div>').html(id.clone()).html();

                window.clipboardData.setData("Text", strCopy);
                var objExcel = new ActiveXObject("Excel.Application");
                objExcel.visible = false;

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


            }

            </script>



</body>

</html>
Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
user2465036
  • 351
  • 2
  • 11
  • 24
  • 6
    I'm sure it calls it but throws an error. `ActiveXObject` only exists in IE. Maybe you are interested in this question: [JavaScript: ActiveXObject in Firefox or Chrome (not IE!)](http://stackoverflow.com/q/7022568/218196). Also, you seem to be using jQuery, but you don't include it. – Felix Kling Aug 06 '13 at 18:55
  • 1
    What's your console say? – tymeJV Aug 06 '13 at 18:55
  • The first thing I do with this sort of errors is to either replace the function call with an `alert()`, or put an `alert()` at the *very* beginning of the function. It's an easy test (usually) to make sure the call gets made, then you can debug from there. – user Aug 06 '13 at 18:56
  • It doesnt call the javascript function. @Felix Kling – user2465036 Aug 06 '13 at 18:56
  • 1
    @user2465036: Assuming you included jQuery, it does for me: http://jsfiddle.net/JCZ8K/. But as I said, the function makes use features that don't exist in Chrome (`window.clipboardData` doesn't seem to exist in Chrome either). I don't have experience with `ActiveXObject`, so I cannot tell you whether you can make it work in Chrome at all, but fact is that the function *does* get called. – Felix Kling Aug 06 '13 at 18:58
  • Sorry Felix King to reply you late .It does call the fucntion ,as you said ActiveX is not supported in chrome – user2465036 Aug 06 '13 at 19:04

0 Answers0