Click or drag to resize

ExtensionAddElements Method

Adds OpenXML elements to a OpenXML element

Namespace:  SOWIDocument.Word
Assembly:  SOWIDocument.Word (in SOWIDocument.Word.dll) Version: 22.2.10.1 (22.2.10.450)
Syntax
public static OpenXmlElement AddElements(
	this OpenXmlElement pRoot,
	IEnumerable<OpenXmlElement> pListToAdd
)

Parameters

pRoot
Type: OpenXmlElement
OpenXML element to add elements
pListToAdd
Type: System.Collections.GenericIEnumerableOpenXmlElement
List of OpenXML elements to add

Return Value

Type: OpenXmlElement
Gives OpenXML element include added elements

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type OpenXmlElement. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).
Examples
This example add line break and text to last paragraph
/* create OpenXML elements *
    <w:p>
      <w:r>
        <w:br/>
        <w:t>Test text for test case Extension method AddElements</w:t>
      </w:r>
    </w:p>*/

DocumentFormat.OpenXml.Wordprocessing.Paragraph lParagraph = new DocumentFormat.OpenXml.Wordprocessing.Paragraph();
DocumentFormat.OpenXml.Wordprocessing.Run lRrun = new DocumentFormat.OpenXml.Wordprocessing.Run();
DocumentFormat.OpenXml.Wordprocessing.Text lText = new DocumentFormat.OpenXml.Wordprocessing.Text
{
    Text = "Test text for test case Extension method AddElements"
};
lRrun.Append(new DocumentFormat.OpenXml.Wordprocessing.Break());
lRrun.Append(lText);
lParagraph.Append(lRrun);

var lParagraphs = this.MyDocument.MainDocumentPart.Document.Body.Descendants<DocumentFormat.OpenXml.Wordprocessing.Paragraph>();
lParagraphs.Last().AddElements(lParagraph);
MyDocument.MainDocumentPart.Document.Save();
See Also