Skip to main content
A newer version of this page is available.
All docs
V19.1
.NET Framework 4.5.2+
Row

CustomXmlPartCollection.Add(String) Method

Adds a new item with the specified content to the collection of custom XML parts.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v19.1.Core.dll

Declaration

ICustomXmlPart Add(
    string content
)

Parameters

Name Type Description
content String

A string XML to store in the custom XML part.

Returns

Type Description
ICustomXmlPart

A ICustomXmlPart object that is the newly created collection item.

Example

The code below demonstrates several ways to add a custom XML part to the spreadsheet document.

workbook.Worksheets[0].Cells["A1"].Value = "Custom Xml Test";

// Add an empty custom XML part.
ICustomXmlPart part = workbook.CustomXmlParts.Add();
XmlElement elem = part.CustomXmlPartDocument.CreateElement("Person");
elem.InnerText = "Stephen Edwards";
part.CustomXmlPartDocument.AppendChild(elem);

// Add an XML part created from string.
string xmlString = @"<?xml version=""1.0"" encoding=""UTF-8""?>
                        <whitepaper>
                           <contact>
                              <firstname>Roger</firstname>
                              <lastname>Edwards</lastname>
                              <phone>832-433-0025</phone>
                              <address>1657 Wines Lane Houston, TX 77099</address>
                           </contact>
                           <date>2016-05-18</date>
                        </whitepaper>";
workbook.CustomXmlParts.Add(xmlString);

// Add an XML part loaded from a file.
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("Documents\\fishes.xml");
workbook.CustomXmlParts.Add(xmlDoc);
workbook.SaveDocument("Documents\\CustomXmlTest.xlsx");
System.IO.File.Copy("Documents\\CustomXmlTest.xlsx", "Documents\\CustomXmlTest.xlsx.zip", true);
System.Diagnostics.Process.Start("Documents\\CustomXmlTest.xlsx.zip");
See Also