![](/img/trans.png)
[英]How to copy the content of one word document into another word document?
[英]Copy content of word document Sections
在我的应用程序中,我正在使用Microsoft.Office.Interop.Word将内容写入Word文档。
var wordApplication = new Word.Application { Visible = true };
var document = wordApplication.Documents.Add();
document.Activate();
每隔1分钟,我将在新部分中为该文档写几行。 即,每5分钟开始在Word文档中添加一个新部分,并将光标移至该部分,然后编写内容。
document.Sections.Add();
wordApplication.ActiveWindow.Selection.GoTo(Word.WdGoToItem.wdGoToPage, Word.WdGoToDirection.wdGoToLast);
每隔10分钟,我需要在后台运行一个线程,并将每个部分中可用的内容复制到远程位置的不同文本文件中。
我的问题是,我无法访问各个部分。 建议一种将每个部分的文本复制到单独的变量或数组中的方法。
这为我工作:
System.Collections.ArrayList al = new System.Collections.ArrayList();
int mycount = 0;
foreach (Microsoft.Office.Interop.Word.Section section in document.Sections)
{
al.Insert(mycount, section.Range.Text.ToString());
mycount++;
}
mycount = 0;
while (mycount < al.Count)
{
MessageBox.Show(" Section Text " + al[mycount].ToString());
mycount++;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.