问题
I'm working with OpenXml and C#, I'm was using bookmarks but now might be switching over to Rich Text Controls. I was able to locate and work with the bookmarks, but i'm having some issues locating the Rich Text Controls. I'm trying the below:
IEnumerable<SdtBlock> contentControlsDoc = null;
((MainDocumentPart)section).Document.Body.Descendants<SdtBlock>();
foreach (var contentControl in contentControlsDoc)
{
}
I'm able to get 1 control, but sometimes I have a Rich Text Control within another, is there anyway to get them all together from the document. Also is there a way to locate them by the Title or Tag id I gave them in Word?
回答1:
Just use:
document.Controls.OfType<RichTextContentControl>().FirstOrDefault(rtcc => rtcc.ID = id);
to access a RichTextContenControl by Id.
来源:https://stackoverflow.com/questions/31880857/navigating-rich-text-control-in-openxml