//设置文件过滤器 if (FileFormat == "Microsoft Word") { saveFileDialog.Filter = "Word 文档(*.docx)|*.docx"; } else { saveFileDialog.Filter = "Excl 工作薄(*.xlsx)|*.xlsx"; } /******************显示文件保存对话框*****************/ if (saveFileDialog.ShowDialog() == DialogResult.OK) { if (FileFormat == "Microsoft Word") { mMyDataTable = (DataTable)BookInformationDataGridView.DataSource; if (mMyDataTable != null && mMyDataTable.Rows.Count > 0) { //修改过添加了_ MSWord._Application WordApp; MSWord._Document WordDoc; Object Path = saveFileDialog.FileName;//路径 WordApp = new MSWord.ApplicationClass();//初始化 if (File.Exists((string)Path))//如果已存在,则删除 { File.Delete((string)Path); } Object Nothing = Missing.Value;//由于yongCOM组件很多值需要用Missing.Value代替 WordDoc = WordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing); //定义一个word表格