[]
        
(Showing Draft Content)

ICustomXmlPart

Interface ICustomXmlPart


public interface ICustomXmlPart
Represents a Custom XML part in a workbook.

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();
 
  • Method Summary

    Modifier and Type
    Method
    Description
    byte[]
    Gets the raw data stored in the Custom XML part.
    Gets the unique ID of the Custom XML part.
    void
    setData(byte[] data)
    Sets the raw data stored in the Custom XML part.
  • Method Details

    • getId

      String getId()
      Gets the unique ID of the Custom XML part.

      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);
       
      Returns:
      The unique ID of the Custom XML part.
    • getData

      byte[] getData()
      Gets the raw data stored in the Custom XML part.

      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);
       
      Returns:
      The raw Custom XML part data.
    • setData

      void setData(byte[] data)
      Sets the raw data stored in the Custom XML part.

      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");
       
      Parameters:
      data - The raw Custom XML part data.