0

我想从 StdContentComboBox 中获取选定的值,这是放置在 docx 文档中的内容控件。我需要在 .NET 中获取选定的值,谢谢

4

1 回答 1

0

尝试这个:

using (WordprocessingDocument myDoc = WordprocessingDocument.Open("yourDocPath", true))
{
    var sdtElements = myDoc.MainDocumentPart.Document.Body.Descendants<SdtElement>();
    var contentControlsWithComboBoxes = sdtElements.Where(x => x.SdtProperties.Elements<SdtContentComboBox>().Any());

    var contentRuns =
        contentControlsWithComboBoxes.Select(x => x.Elements<SdtContentRun>());
    var selectedValues  = contentRuns.Select(x => x.FirstOrDefault().InnerText); // Your selected combobox values 

}
于 2013-02-19T16:50:06.673 回答