【问题标题】:Is there a way to get the content from content controls in a word document?有没有办法从 word 文档中的内容控件中获取内容?
【发布时间】:2020-08-18 15:54:18
【问题描述】:

利用这个

Application app = new Application();

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

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

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

【问题讨论】:

    标签: c# ms-word office-interop word-contentcontrol


    【解决方案1】:

    通过使用它来工作:

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

    【讨论】:

      猜你喜欢
      • 2022-12-02
      • 1970-01-01
      • 2010-09-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-06
      • 1970-01-01
      相关资源
      最近更新 更多