----服务器的Application环境需配置
var product_list =[];
---product_list赋值;
var filename = "文档模板.docx"; var filernd = "upload/temp/"+Session.SessionId.toString()+parseInt(Math.random()*1000000)+".docx"; var fso = new ActiveXObject( "Scripting.FileSystemObject" ); var source = Server.MapPath(filename); var destination = Server.MapPath(filernd); fso.CopyFile(source, destination, true); var t = false; var wordApp = new ActiveXObject("Word.Application"); try{ wordApp.Visible = false; wordApp.Documents.Open(destination); //WriteLn(destination); var wordArange = wordApp.ActiveDocument.Content; wordArange.Find.Execute("{date0}", false, false, false, false, false, false, 1, true, date0, 2); wordArange.Find.Execute("{date1}", false, false, false, false, false, false, 1, true, date1, 2); wordApp.ActiveDocument.Select(); //如果product数组过长需加以下代码 if( wordApp.Selection.Find.Execute("{product_list}", false, false, false, false, false, false, 1, true ) ){ wordApp.Selection.TypeText(Str4Html(product_list)); } wordApp.ActiveDocument.Save(); wordApp.Quit(); }catch(e){ }