从JavaScriptclosuresExcel ActiveX对象在内存中保留excel.exe

function gbid(s) { return document.getElementById(s); } function GetData(cell,row) { var excel = new ActiveXObject("Excel.Application"); var excel_file = excel.Workbooks.Open("Z:/SunCenter/Medicare Customer Experience/Hub/CaliforniaHUB/Plans/H0562_2013_082_EOC.xlsx"); var excel_sheet = excel.Worksheets("Sheet1"); gbid('span1').innerText = excel_sheet.Cells(1191,1).Value; gbid('span2').innerText = excel_sheet.Cells(1192,1).Value; gbid('span3').innerText = excel_sheet.Cells(1192,3).Value; excel_file.Close() excel.Quit() } 

每当JavaScript运行(onload),它将在taskmanager / Processes中创build一个进程。 问题是使用后不会closures它。 当我再次运行它时,会创build另一个。 现在它只是从excel文件中提取信息,这个文件工作的很好,但是它只是不会closurestaskmanager中的exe文件。 我以为excel_file.close会这样做,我甚至把另一个, excel.quit ,以防万一。 对不起,我只是想确保它的工作。 我甚至现在只是在冲突的情况下拿走了一个,但拿破仑。 任何帮助?

你需要调用excel.Application.Quit(); 而不只是excel.Quit();

根据微软的说法,因为当你调用Quit()时,你仍然持有对excel的引用,所以Excel不能干净地closures。 build议调用Quit() ,设置excel = null ,然后在短暂的等待之后运行CollectGarbage

 var idTmr = ""; function GetData() { //... excel.Quit(); excel = null; idTmr = window.setInterval("Cleanup();",1); } function Cleanup() { window.clearInterval(idTmr); CollectGarbage(); } 

原始来源:

http://support.microsoft.com/kb/266088

Windows 7小工具不释放ActiveX对象