我想將一個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