Copying contents of Word doc and paste into another

六眼飞鱼酱① 提交于 2019-11-29 05:02:07
jenny

You can do this:

object docStart = worddocpromo.Content.End - 1;
object docEnd = worddocpromo.Content.End;

object start = SubDoc.Content.Start;
object end = SubDoc.Content.End;

SubDoc.Range(ref start, ref end).Copy();
Microsoft.Office.Interop.Word.Range rng = worddocpromo.Range(ref docStart, ref docEnd);
rng.Paste();

You can do this:

    Word.Application word = new Word.Application();
    word.Visible = true;
    Word.Document d1 = word.Documents.Add();
    Word.Document d2 = word.Documents.Open(@"E:\00-Word\Test.docx");
    Word.Range oRange = d2.Content;
    oRange.Copy();
d1.Content.PasteSpecial(DataType:Word.WdPasteOptions.wdKeepSourceFormatting);
Divi

This link should help.

Duplicating Word document using OpenXml and C#

Another suggestion is to creating a copy of the word file and renaming it to whatever the required name is, if that suits your soluition.

http://www.dotnetperls.com/file-copy

If you need to access older Word documents (Word 97 etc), there are third-party libraries available which give you full control over creating and amending the documents without having Word installed on the target machine. This is especially useful for web servers.

We have used Essential DocIO from Syncfusion successfully in the past - http://www.syncfusion.com/products/reporting-edition/docio

Otherwise, you can use the Microsoft Office Automation libraries to access older Word documents - http://support.microsoft.com/kb/301659

There are quite a few things you have to be careful with when using the automation libraries since they execute Word directly on the target machine. Running them on a web server is a big no-no.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!