1

I am using following code to extract data from excel sheet using javascript. This is working good and after opening the HTML page, getting the data that I want and closing the page, I am unable to open and edit the excel sheet as it is throwing the exception, "File already held by the user and unable to be edited". Is there anyway to handle the closing of excel sheet at the end of the code? Please help me.

<!DOCTYPE html>
<html>
<body>

Enter Salomon account:<br>
<input type="text" id="myText" name="SalAccount">
<br>
<button onclick="myFunction()">Submit</button>

<p id="demo"></p>

<script language="javascript" >

function myFunction() 
{
alert("hello");
var excel = new ActiveXObject("Excel.Application");
var excel_file = excel.Workbooks.Open("C:/Users/bv15457/Desktop/test1.xlsx");
var excel_sheet = excel.Worksheets("Sheet1");

var x = document.getElementById("myText").value;

var lo = 1;
var hi = 682220;
var mid;
var element;
var Flag = 0;

while(lo <= hi && Flag != 1)
{
    mid = Math.floor((lo + hi) / 2, 10);
    element = excel_sheet.Cells(mid,1).Value;
    if (element < x)
    {
        lo = mid + 1;
    }
    else if (element > x) 
    { 
        hi = mid - 1;
    }
    else
    {
        document.getElementById("demo").innerHTML = excel_sheet.Cells(mid,2).Value;
        Flag = 1;
    }
}

if (Flag != 1)
{
    alert("Account is not found in XREF file");
}

}
</script>
</body>
</html>
Vamsi Krishna
  • 11
  • 1
  • 2
  • possible duplicate of [Closing Excel ActiveX object from JavaScript leaves excel.exe in memory](http://stackoverflow.com/questions/17309231/closing-excel-activex-object-from-javascript-leaves-excel-exe-in-memory) – Muhammad Bilal Feb 02 '15 at 06:37

0 Answers0