Anuj
Anuj

Reputation: 23

How to Get Paragraph List's all run elements as a List from OpenXml

Hi I have List of OpenXmlElement List<OpenXmlElement> which is of Paragraphs of OpenXMLElement and I want to get all the runs from List of Paragraphs.

List<OpenXmlElement> oFieldNodes = GetParagraphs();
// this will return first paragraph's all runs.
List<Run> oRuns = oFieldNodes[0].Descendants<Run>().ToList<Run>(); 

How can I get List of Runs from all the Paragraphs from oFieldNodes using lambda expression or linq.

Any help will be appreciated. Thanks

Upvotes: 2

Views: 1474

Answers (1)

petelids
petelids

Reputation: 12815

You can use SelectMany

List<Run> oRuns = oFieldNodes.SelectMany(o => o.Descendants<Run>()).ToList<Run>();

Upvotes: 1

Related Questions