{ MessageBox.Show(ex.Message); } finally { doc.Save();//save word CloseApp();//close word app CopyExcelData();//copy data again,******************* } } 关于关闭word对象 public void CloseApp() { WordApp.Documents.Close(ref trueValue, ref missing, ref missing); WordApp.Quit(ref trueValue, ref missing, ref missing); System.Runtime.InteropServices.Marshal.ReleaseComObject(WordApp); GC.Collect(); //this.KillExcelProcess(); } 还有两个工具函数不再赘述,用来copy文件并且返回文件名private string CopyExcelData();和private string CopyTemplateDoc()。 |