如何找到段落节点在OpenXML的表节点内

时间:2015-03-17 05:05:01

标签: c# openxml

我在下面的代码示例中尝试使用Ancestor属性来查找表节点中的段落节点,但它并不适用于所有情况。

using (WordprocessingDocument Docx = WordprocessingDocument.Open(DocxStream, true))
{
    Body DocxBody = Docx.MainDocumentPart.Document.Body;
    List<OpenXmlElement> EachPara = new List<OpenXmlElement>();//Paragraph element
    foreach (OpenXmlElement bodyChild in DocxBody.ChildElements)
    {
        if (bodyChild is Paragraph)
        {
            if (bodyChild.Ancestors<Table>().ToList().Count > 0)
            {

            }
        }
    }
    //  List<OpenXmlElement> EachPara = DocxBody.ChildElements.ToList().Where(eachChild => eachChild is Paragraph).ToList();
    foreach (OpenXmlElement lstPara in EachPara)
    {
        if (lstPara.ChildElements.Any(ch => ch.LocalName.ToLower().Equals("run")))
        {

        }
        else
        {
        }
    }

}

0 个答案:

没有答案