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

问题描述

通过利用

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

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...