Navigating Rich Text Control in OpenXml

て烟熏妆下的殇ゞ 提交于 2020-01-07 09:04:07

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!