我想将一个word文档动态复制到另一个word文档。这个过程可以在按钮点击中完成。文档(文档)包含的文字,我想将它复制到文件(docs2)如何使用c将文本从一个Word文档复制到另一个Word文档#
public void ReadMsWord()
{
string filePath = null;
OpenFileDialog file = new OpenFileDialog();
file.Title = "Word File";
file.InitialDirectory = "c:\\";
file.RestoreDirectory = true;
if (file.ShowDialog() == DialogResult.OK)
{
filePath = file.FileName.ToString();
}
try
{
//Microsoft.Office.Interop.Word.Application Oword = new Microsoft.Office.Interop.Word.Application();
//Oword.Visible = true;
var templatepath = filePath;
var wordapp = new Microsoft.Office.Interop.Word.Application();
var orgnldoc = wordapp.Documents.Open(templatepath);
orgnldoc.ActiveWindow.Selection.WholeStory();
orgnldoc.ActiveWindow.Selection.Copy();
var newdcmnt=new Microsoft.Office.Interop.Word.Document();
newdcmnt.ActiveWindow.Selection.Paste();
newdcmnt.SaveAs(@"C:\Users\Documents\TestDoc2.docx");
System.Runtime.InteropServices.Marshal.ReleaseComObject(wordapp);
System.Runtime.InteropServices.Marshal.ReleaseComObject(orgnldoc);
System.Runtime.InteropServices.Marshal.ReleaseComObject(newdcmnt);
GC.Collect();
}
catch (Exception ex) { MessageBox.Show(ex.ToString()); }
}
通过你的问题是我们都有自己的需求和欲望,但我看不出有问题的代码这里是 – MethodMan 2013-03-20 13:01:20
什么是错误?你尝试了什么? – evgenyl 2013-03-20 13:01:44
方法'PasteSpecial'没有超载需要1个参数 – user2173324 2013-03-20 13:06:02