





{
ApplicationClass vWordApplication = new ApplicationClass();
// string strTemplateName = "UserDoc//"+this.projid+"//"+"资料归档"+"//55.doc";
strTemplateName = HttpContext.Current.Server.MapPath(strTemplateName);
object vFileName = strTemplateName;
object vReadOnly = false;
object vIsVisible = true;
object vMissing = Missing.Value;
Document vDocument = vWordApplication.Documents.Open(ref vFileName, ref vMissing, ref vReadOnly, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vIsVisible, ref vMissing, ref vMissing, ref vMissing, ref vMissing);
vDocument.Activate();
vWordApplication.Visible = false;
object pBreak = (int)Word.WdBreakType.wdPageBreak;
for (int i = 0; i < filepath.Length; i++)
{
string strFileName;
strFileName = HttpContext.Current.Server.MapPath(filepath[i].ToString());
vWordApplication.Selection.InsertFile(strFileName, ref vMissing, ref vMissing, ref vMissing, ref vMissing);
{
string strFileName;
strFileName = HttpContext.Current.Server.MapPath(filepath[i].ToString());
vWordApplication.Selection.InsertFile(strFileName, ref vMissing, ref vMissing, ref vMissing, ref vMissing);
vWordApplication.Selection.InsertBreak(ref pBreak);//插入分页符
}
vDocument.SaveAs(ref vFileName, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing);
//关闭WordDoc文档对象
vDocument.Close(ref vMissing, ref vMissing, ref vMissing);
//关闭WordApp组件对象
}
vDocument.SaveAs(ref vFileName, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing, ref vMissing);
//关闭WordDoc文档对象
vDocument.Close(ref vMissing, ref vMissing, ref vMissing);
//关闭WordApp组件对象
if (vDocument != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(vDocument);
vDocument = null;
}
if (vDocument != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(vDocument);
vDocument = null;
}
GC.Collect();
return true;
}
catch
{
return false;
}
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(vDocument);
vDocument = null;
}
if (vDocument != null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(vDocument);
vDocument = null;
}
GC.Collect();
return true;
}
catch
{
return false;
}


#region 杀死word进程
private void KillProcess(string processName)
{
System.Diagnostics.Process myproc = new System.Diagnostics.Process();
//得到所有打开的进程
try
{
foreach (Process thisproc in Process.GetProcessesByName(processName))
{
if (!thisproc.CloseMainWindow())
{
thisproc.Kill();
}
}
}
catch (Exception Exc)
{
//msg.Text += "杀死" + processName + "失败!";
}
}
#endregion
private void KillProcess(string processName)
{
System.Diagnostics.Process myproc = new System.Diagnostics.Process();
//得到所有打开的进程
try
{
foreach (Process thisproc in Process.GetProcessesByName(processName))
{
if (!thisproc.CloseMainWindow())
{
thisproc.Kill();
}
}
}
catch (Exception Exc)
{
//msg.Text += "杀死" + processName + "失败!";
}
}
#endregion
