<script language=javascript>
var xlApp,xlBook,xlSheet;
xlApp = new ActiveXObject("Excel.Application");
xlBook = xlApp.Workbooks.Add();
xlSheet = xlBook.Worksheets(1);
xlSheet.Cells(1,1).Value = "测试";
xlSheet.Application.Visible = true;
xlApp.DisplayAlerts = false;
xlBook.Close();
xlApp.DisplayAlerts = true;
xlApp.Quit();
</script>
脚本运行完毕之后,还有一个excel大约20M的进程在内存中运行,怎么办?
解决办法
<HTML>
<BODY>
<INPUT type="button" value="Automate Excel" name=AutomateExcel οnclick="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>
参见
http://support.microsoft.com/kb/266088/en-us
--------------------------------------------------------------------------------