繁体   English   中英

有没有办法从 word 文档中的内容控件中获取内容?

[英]Is there a way to get the content from content controls in a word document?

通过利用这个

Application app = new Application();

Document doc = app.Documents.Open(path, ReadOnly: false, Visible: false);

var test = doc.SelectContentControlsByTag("CK");

我得到每个带有标签“CK”的内容控件,在我的例子中它只有一个。 如何让内容脱离测试?

通过使用这个来工作:

 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;
            }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM