IWorkbook.CustomXmlParts Property
Provides access to the collection of custom XML parts in the document.
Namespace: DevExpress.Spreadsheet
Assembly: DevExpress.Spreadsheet.v18.2.Core.dll
Declaration
Property Value
Type | Description |
---|---|
CustomXmlPartCollection | A CustomXmlPartCollection object that is the collection of embedded arbitrary XML data (custom XML parts). |
Remarks
A document in OpenXml (.xlsx) format consists of XML files within folders packed in a ZIP archive. Most of the XML files are built-in parts that define the document structure and hold its content. However, documents can also contain custom XML parts, which you can use to store arbitrary XML data.
The folder that contains custom XML parts is located in the document structure as shown in the following picture. There are two custom XML parts clearly identified as item1 and item2.
You can use the CustomXmlPartCollection.Add method to store an XML string or a XmlDocument document as the document’s custom XML part.
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");