[]
A Custom XML part stores an arbitrary XML payload as raw bytes in the workbook package. The part is identified by a generated ID that is persisted with the workbook and can be used to retrieve the part after reopening the file.
ICustomXmlPart customXmlPart = workbook.getCustomXmlParts().add();
customXmlPart.setData("<order><id>1001</id></order>"
.getBytes(java.nio.charset.StandardCharsets.UTF_8));
String id = customXmlPart.getId();
byte[] xmlData = customXmlPart.getData();
The ID is generated when the part is added to the workbook and is stored in the Custom XML part properties. Use this value with ICustomXmlPartCollection.get(String) to retrieve the same part after the workbook is saved and reopened.
ICustomXmlPart customXmlPart = workbook.getCustomXmlParts().add();
String id = customXmlPart.getId();
ICustomXmlPart samePart = workbook.getCustomXmlParts().get(id);
The returned byte array is a copy of the stored data. Modifying the returned array does not change the content of the Custom XML part. To update the part content, use setData(byte[]).
ICustomXmlPart customXmlPart = workbook.getCustomXmlParts().add();
byte[] xmlData = "<settings><enabled>true</enabled></settings>"
.getBytes(java.nio.charset.StandardCharsets.UTF_8);
customXmlPart.setData(xmlData);
byte[] storedXmlData = customXmlPart.getData();
String xmlText = new String(storedXmlData, java.nio.charset.StandardCharsets.UTF_8);
The provided byte array is copied into the Custom XML part. The data is persisted as the XML payload of the part when the workbook is saved to an OpenXML workbook format.
ICustomXmlPart customXmlPart = workbook.getCustomXmlParts().add();
byte[] xmlData = "<settings><enabled>true</enabled></settings>"
.getBytes(java.nio.charset.StandardCharsets.UTF_8);
customXmlPart.setData(xmlData);
workbook.save("customXmlWorkbook.xlsx");
data - The raw Custom XML part data.