在我的应用程序中,正在使用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++;
}