我试图弄清楚如何确定段落是否隐藏了文本。通过互操作很容易,但我似乎无法在openxml中找到它。非常感谢任何帮助
MainDocumentPart mdp = wordprocessingDocument.MainDocumentPart;
XDocument xDoc = mdp.GetXDocument();
IEnumerable<XElement> = xDoc.Descendants(W.p);
foreach (var paragraph in paragraphs)
{
// I want to check if this paragraph has hidden text or not, if it does I want to skip over it.
// if (paragraph.hasHiddenText()) { continue; }
// else, get the content
string paraText = paragraph.Descendants(W.t).Select(t => (String)t).StringConcatenate();
}
答案 0 :(得分:1)
如果你继续使用open xml sdk而不是linq-to-xml,那就容易了:
MainDocumentPart mdp = wordprocessingDocument.MainDocumentPart;
foreach(var paragraph in mdp.Document.Body.Descendants<Paragraph>())
{
...
string paraText = paragraph.Descendants<Run>()
.Where(r => r.RunProperties.Vanish != null)
.Aggregate("", (text,r) => text += r.InnerText);
}
虽然sdk可能稍慢,但使用起来更方便。除非你每分钟处理数百个文件,否则我不会担心。