To work around this problem, you can call the CollectGarbage method. This forces JScript's garbage collection to occur immediately, which releases the reference to Excel. The following code snippet illustrates how to use the CollectGarbage method: <HTML> <BODY> <INPUT type="button" value="Automate Excel" name=AutomateExcel onclick="StartExcel()"> <SCRIPT LANGUAGE=Javascript> var idTmr = ""; function StartExcel() { var oExcel; oExcel = new ActiveXObject("Excel.Application"); oExcel.Quit(); oExcel = null; idTmr = window.setInterval("Cleanup();",1); } function Cleanup() { window.clearInterval(idTmr); CollectGarbage(); }</SCRIPT> </BODY> </HTML>
{
oXL = new ActiveXObject("Excel.Application");
oWB = oXL.Workbooks.add();
oSheet = oWB.Worksheets(1);
}
catch(e)
{
alert(e.message);
}
finally{
oXL.Quit();
}
CollectGarbage();
}
<HTML>
<BODY>
<INPUT type="button" value="Automate Excel" name=AutomateExcel onclick="StartExcel()">
<SCRIPT LANGUAGE=Javascript>
var idTmr = "";
function StartExcel() {
var oExcel; oExcel = new ActiveXObject("Excel.Application");
oExcel.Quit();
oExcel = null;
idTmr = window.setInterval("Cleanup();",1);
} function Cleanup() {
window.clearInterval(idTmr);
CollectGarbage();
}</SCRIPT>
</BODY>
</HTML>
oXL = null;
delete oXL;
这个地方不合逻辑。但不知道是不是问题所在