打开XML:Word-从sdtBlock-> sdtContent获取所有嵌套表

时间:2019-03-05 18:56:11

标签: c# openxml openxml-sdk

enter image description here

我的Word文档中有这种结构。 需要从SdtBlock-> SdtContentBlock-> Table的正文中检索所有表

 using (WordprocessingDocument formDoc = WordprocessingDocument.Open(destinationFile, true))
        {
            var FirstHeadingParagraph = new List<Paragraph>();
            var SecondHeadingParagraph = new List<Paragraph>();
            FirstHeadingParagraph = formDoc.MainDocumentPart.Document.Body.OfType<Paragraph>()
                                    .Where(p => p.ParagraphProperties != null &&
                                    p.ParagraphProperties.ParagraphStyleId != null &&
                                    p.ParagraphProperties.ParagraphStyleId.Val.Value.Contains("Heading2")).ToList();

            SecondHeadingParagraph = formDoc.MainDocumentPart.Document.Body.OfType<Paragraph>()
                                    .Where(p => p.ParagraphProperties != null &&
                                    p.ParagraphProperties.ParagraphStyleId != null &&
                                    p.ParagraphProperties.ParagraphStyleId.Val.Value.Contains("Heading3")).ToList();

            var AllTable= formDoc.MainDocumentPart.Document.Body.OfType<SdtBlock>().OfType<SdtContentBlock>().OfType<Table>().ToList();

但是得到0个表列表。

0 个答案:

没有答案