Search code examples
jqueryactivexobject

$ is undefined after opening excel ActiveXobject


I have a local html file to do some manipulations with excel. My scripts tags are in head as follows

   <head>
     <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.js"></script>
    <script type="text/javascript">
    var Excel;
    var ExcelSheet = new ActiveXObject("Excel.Sheet");
    function openExcel(){
        Excel = new ActiveXObject("Excel.Application");
        Excel.Visible = true;
        return Excel.Workbooks.Open("C:/Users/Desktop/Temp/Input.xlsx").ActiveSheet;    
    }
    function begin(){
$("div").append("zzzzzzzz");
    ExcelSheet = openExcel();
$("div").append("zzzzzzzz");

}
    </head>

I call function "begin" on button click... The first append gets executed but the second does not.

on console it says "'$' is undefined" after execution. Before excution it finds JQUery I am using IE9


Solution

  • @Braiam Works fine

    <head>
         <script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.js"></script>
        <script type="text/javascript">
        var Excel;
        var ExcelSheet = new ActiveXObject("Excel.Sheet");
        function openExcel(){
            Excel = new ActiveXObject("Excel.Application");
            Excel.Visible = true;
            return Excel.Workbooks.Open("C:/Users/Desktop/Temp/Input.xlsx").ActiveSheet;    
        }
        function begin(){
    $("div").append("zzzzzzzz");
        ExcelSheet = openExcel();
    $("div").append("zzzzzzzz");
    
    }
    </script>
        </head>
    <body>
        <h1>Body has loaded</h1>
        <div></div>
        <input type="button" value="Start" onclick="begin()">
    </body>
    
    </html>