我有一个包含一些文本和图像的Word文档。我想使用C#将word文档的内容复制到另一个word文档中。
Thanks.
尝试下面的代码。这可能对你有帮助。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Office.Interop.Word;
using System.Runtime.InteropServices;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var app = new Microsoft.Office.Interop.Word.Application();
var sourceDoc = app.Documents.Open(@"D:\test.docx");
sourceDoc.ActiveWindow.Selection.WholeStory();
sourceDoc.ActiveWindow.Selection.Copy();
var newDocument = new Microsoft.Office.Interop.Word.Document();
newDocument.ActiveWindow.Selection.Paste();
newDocument.SaveAs(@"D:\test1.docx");
sourceDoc.Close(false);
newDocument.Close();
app.Quit();
Marshal.ReleaseComObject(app);
Marshal.ReleaseComObject(sourceDoc);
Marshal.ReleaseComObject(newDocument);
}
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)