CustomXmlPartCollection.Add(XmlDocument) Method
Adds the specified XML document to the collection of custom XML parts.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v19.1.Core.dll
Declaration
Parameters
Name | Type | Description |
---|---|---|
document | XmlDocument | A System.Xml.XmlDocument object to add to the collection. |
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.
Note
A complete sample project is available at https://github.com/DevExpress-Examples/winforms-spreadsheetcontrol-api-part-3-t231273
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