如何使用Word.Application oWord复制1页并将其作为新页面粘贴到另一个文档中 [英] How to copy 1 page and paste it to as new pages into another document by using Word.Application oWord
问题描述
好的我想要实现的很简单
Ok what i want to achieve is simple
我创建了一个模板2003 Doc
I have created a template 2003 Doc
只有1页。所以我目前所做的是复制整个内容(只有1页),更改值并将其粘贴到另一个文档中。但是为了循环,我想粘贴到新页面。所以最后,我的最终文档在这个例子中应该有2页
It is only 1 page. So what i do currently is copy entire content (it is only 1 page), change the value and paste it into another document. But withing for loop, i want to paste into new pages. So at the end, my final document should have 2 pages in this example
请帮忙谢谢
Please help thank you
string filename = @"D:\18_babam_dosyalar\Anket Olusturma\Anket Olusturma\bin\debug\1.doc";
Microsoft.Office.Interop.Word.Application oWord = new Microsoft.Office.Interop.Word.Application();
Microsoft.Office.Interop.Word.Document oDoc2 = oWord.Documents.Add();
for (int i = 1; i < 3; i++)
{
Microsoft.Office.Interop.Word.Document oDoc1 = oWord.Documents.Open(filename);
object matchCase = false;
object matchWholeWord = true;
object matchWildCards = false;
object matchSoundsLike = false;
object matchAllWordForms = false;
object forward = true;
object format = false;
object matchKashida = false;
object matchDiacritics = false;
object matchAlefHamza = false;
object matchControl = false;
object read_only = false;
object visible = true;
object replace = 2;
object wrap = 1;
object findText = "#";
object replaceWithText = i.ToString();
//execute find and replace
oDoc1.Content.Find.Execute(ref findText, ref matchCase, ref matchWholeWord,
ref matchWildCards, ref matchSoundsLike, ref matchAllWordForms, ref forward, ref wrap, ref format, ref replaceWithText, ref replace,
ref matchKashida, ref matchDiacritics, ref matchAlefHamza, ref matchControl);
Microsoft.Office.Interop.Word.Range oRange = oDoc1.Content;
oRange.Copy();
//I need to paste this range into the ith page. so if i=1 paste into first page, i=2 paste into second page
oDoc2.Content.PasteSpecial(DataType: Microsoft.Office.Interop.Word.WdPasteOptions.wdKeepSourceFormatting);
oDoc1.Close();
}
object outputFileName = @"D:\18_babam_dosyalar\Anket Olusturma\Anket Olusturma\bin\debug\final2.doc";
oDoc2.SaveAs(ref outputFileName);
oWord.Quit();
基于浏览器< a href =" http://www.monstermmorpg.com"> Pokemon< / a>风格MMORPG游戏开发者使用asp.net 4.0路由它的< a href =" http://www.monstermmorpg.com/MonsterDex">怪物< / a>
Browser based <a href="http://www.monstermmorpg.com">Pokemon</a> Style MMORPG Game Developer Used asp.net 4.0 routing at it's <a href="http://www.monstermmorpg.com/MonsterDex">Monsters</a>
推荐答案
您好MonsterMMORPG,
Hello MonsterMMORPG,
我建议您将oRange内容提交到文档末尾,请尝试替换
I would suggest suggest you past the oRange content to the end of the document, please try to replace
oDoc2.Content.PasteSpecial(DataType: Microsoft.Office.Interop.Word.WdPasteOptions.wdKeepSourceFormatting);
=>
//If your document has content already and you want to paste these content in separte page, you could un-comment out below line code
//oDoc2.Range(oDoc2.Content.End - 1, oDoc2.Content.End - 1).InsertBreak(Word.WdBreakType.wdPageBreak);
oDoc2.Range(oDoc2.Content.End - 1, oDoc2.Content.End - 1).Paste();
最好的问候,
Terry
这篇关于如何使用Word.Application oWord复制1页并将其作为新页面粘贴到另一个文档中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!