【发布时间】:2018-01-22 15:00:11
【问题描述】:
while (doc.ActiveWindow.Selection.Bookmarks.Exists(@"\EndOfDoc") == false)
{
//Skiping table content and proceeding with only paragraphs
if (doc.ActiveWindow.Selection.get_Information(WdInformation.wdWithInTable) == false)
{
doc.ActiveWindow.Selection.EndKey(ref wdLine, ref wdExtend);
currLine = doc.ActiveWindow.Selection.Text;
temp = currLine;
// Move to next line after assigning to temp
doc.ActiveWindow.Selection.MoveDown(ref wdLine, ref wdCountOne, ref wdMove);
doc.ActiveWindow.Selection.HomeKey(ref wdLine, ref wdMove);
//<Match some text on paragraph>
if (temp.StartsWith(searchValue))
{
resultValue = temp;
break;
}
}
else //If its a table
{
// navigate to next line
while (doc.ActiveWindow.Selection.get_Information(WdInformation.wdWithInTable) == true)
{
if (doc.ActiveWindow.Selection.Bookmarks.Exists(@"\EndOfDoc"))
break;
doc.ActiveWindow.Selection.MoveDown(ref wdLine, ref wdCountOne, ref wdMove);
doc.ActiveWindow.Selection.HomeKey(ref wdLine, ref wdMove);
}
doc.ActiveWindow.Selection.MoveDown(ref wdLine, ref wdCountOne, ref wdMove);
doc.ActiveWindow.Selection.HomeKey(ref wdLine, ref wdMove);
}
}
我是 C# 新手,我正在尝试使用 Interop 阅读 word 文档,但这样做时,我被困在文档中存在的嵌套表中,并且控件无限期地围绕该表循环。这里的问题似乎是它无法从表中出来,因此无法找到“\EndOfDoc”书签。非常感谢任何有关离开餐桌并进行进一步处理的帮助。
【问题讨论】:
-
表格中的内容应该如何处理?您似乎没有对内容进行任何处理?你想跳过表格吗?
-
是的。我想跳过整个表格并继续下一段
-
我的回答对您有帮助吗?您是 StackOverflow 的新手,所以我觉得我应该提一下,对于该网站的其他用户来说,在 cmets 和 Answers 中标记“答案”并为有用的贡献投票是很重要的。
标签: c# ms-word office-interop