通过利用
Application app = new Application();
Document doc = app.Documents.Open(path, ReadOnly: false, Visible: false);
var test = doc.SelectContentControlsByTag("CK");
我得到的每个内容控件都带有标签“ CK”,在我看来,它只是一个。 如何使内容过测试?
答案 0 :(得分:0)
使用以下方法使它起作用:
using (WordprocessingDocument doc =
WordprocessingDocument.Open(path, false))
{
List<SdtBlock> sdtSubTable = doc.MainDocumentPart.Document.Body.Descendants<SdtBlock>().Where
(r => r.SdtProperties.GetFirstChild<Tag>().Val.Value.Equals(tag)).ToList();
return sdtSubTable[0].SdtContentBlock.InnerText;
}