2

I know this types of question doesn't belong to here but this is my last hope to get answer and solution for this. I had made a html and javascript program to read excel file through Active X, but problem is that whenever I run that page the it runs fine but when i closed it the excel file remain open and if I run this page 100 times and then close it then there will be 100 unclosed excel file which leads to slowdown my PC. And second problem is that when I try to open that excel file which is being used by that application(the application is not currently running when i tried to open excel file) it does not open without giving an error,an window of excel file open and closed with in a small part of second..I don't know what to do to resolve this. If there is any problem in my code then here it is

    var xVal = 1;
    var yVal = 2

    function readdata(x,y) {
        x = xVal;
        y = yVal;
        try {
            var excel = new ActiveXObject("Excel.Application");
            excel.Visible = false;
            var excel_file = excel.Workbooks.Open("D:\\Test1.xls");// alert(excel_file.worksheets.count);
            var excel_sheet = excel_file.Worksheets("Sheet1");
            var data = excel_sheet.Cells(x, y).Value;
            //alert(data);
            drawWithexcelValue(data);

            xVal = xVal + 1;

        }

        catch (ex) {
            alert(ex);
        }
    }

this is the code through which I am reading the excel file.

4
  • 1
    Try adding excel.Quit() at the end. Commented Jul 22, 2013 at 18:07
  • where should i add this in my program ,because i tried it already but it doesn't helped.. Commented Jul 22, 2013 at 18:10
  • I would add it before the closing } of the readdata function. Commented Jul 22, 2013 at 18:13
  • if i do this then every time the value is incremented then the excel file will be closed ..and FYI i did that ,even in if else condition but it won't help Commented Jul 22, 2013 at 18:15

1 Answer 1

1

Try

data = null;
excel_sheet = null;
excel_file.Close();    // important
excel_file = null;
excel.Quit();
excel = null;

in this (reverse) order. This is (almost) equivalent to setting these values to Nothing in VBA.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.