我的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个表列表。