4

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

Rigel
  • 882
  • 1
  • 11
  • 32
  • 1
    Could you please test if it will work if you use `jQuery("div").append("zzzzzzzz")` instead of just writing `$("div").append("zzzzzzzz")` (just to be sure that it is only a problem with the `$`) ? – t.niese Jun 27 '13 at 09:54
  • 4
    your inline `script` tag is not closed, I see `head` close instead – Tommi Jun 27 '13 at 10:14
  • maybe the active x object is appending a second Jquery file, it will cause $ to be undefined? – Remo H. Jansen Jun 27 '13 at 10:22
  • @OweRReLoaDeD jquery is too smart for not to kill itself – Ivan Chernykh Jun 27 '13 at 10:27
  • Thank you. I got it fixed. I dont knwo how. I make a clean new file imported jquery and migrated my code chuck by chunck out of desperation. :S. And it works. i guess it was due to excel was in read only mode. – Rigel Jun 27 '13 at 17:24
  • Excel might be using `$` as a global variable since it's commonly used when referencing cells. It's a really crappy implementation, but then again, it's ActiveX. What happens if you put it inside it's own closure and not in the window scope? – mekwall Jul 01 '13 at 10:00
  • @Rigel care to show the final result? – Braiam Jul 07 '13 at 04:54

1 Answers1

1

@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>
Rigel
  • 882
  • 1
  • 11
  • 32