Need example of using CustomXmlParts

I’m trying to access CustomXMLParts from an Excel file.


According to this post that mentioned it but that person only needed access to the custom document properties which is a subset of the CustomXMLParts.

Below is an example of using an Excel add-in to create a CustomXMLPart where Wb is a Microsoft.Office.Interop.Excel.Workbook:

CustomXMLPart cxp = Wb.CustomXMLParts.SelectByNamespace("`http://my.namespace.com`").Cast<CustomXMLPart>().FirstOrDefault();

if (cxp == null)
{
cxp = Wb.CustomXMLParts.Add(“<MyXmlData1 xmlns="http://my.namespace.com"/>”);
Debug.WriteLine("Id: " + cxp.Id);
Debug.WriteLine("NamespaceURI: " + cxp.NamespaceURI);
Debug.WriteLine("XML: " + cxp.XML);
}

Debug.Assert(Wb.CustomXMLParts.SelectByNamespace(http://my.namespace.com).Cast<CustomXMLPart>().Any(), “Expected CustomXMLPart to be found”);


I’m attaching an Excel document that includes the XML added in the above example.

I need to be able to add, read, and update a custom xml section both within an Excel add-in and using Aspose.Cells. If the CustomXMLParts is not implemented in Aspose.Cells, what alternatives are there for storing xml within a workbook? The XML is being used to implement data bindings to an external source.

Thank you.

Hi,

Thanks for your posting and using Aspose.Cells.

Aspose.Cells allows you to work with Custom XML parts. However in order to investigate it, we need your screenshots showing your Custom XML parts and the steps you perform Microsoft Excel to view or edit them. We will look into your issue and help you asap. Thanks for your cooperation.

The CustomXMLParts can be viewed in the attachment of my original post. Open the zip file, and within the customXml folder are two xml files the were created with example code. I’ve also attached the two xml files to this post and replicated their contents below.


item1.xml:

itemProps1.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<ds:datastoreItem ds:itemID="{1D3CF2F4-9155-40AE-99F6-33298D217F89}" xmlns:ds="http://schemas.openxmlformats.org/officeDocument/2006/customXml">
<ds:schemaRefs>
<ds:schemaRef ds:uri="http://my.namespace.com"/>
</ds:schemaRefs>
</ds:datastoreItem>

Note that Aspose.Words has a CustomXmlParts property on the Document class (link). I expected that Aspose.Cells would have the same property but it is not present in v8.6.3.

Please let me know if you’d like additional information.

Thank you.

Hi,

Thanks for your nice detailed description and considering Aspose.Cells.

We are afraid this feature is not available in the Aspose.Cells. Therefore we have logged it as a New Feature request in our database for investigation and implementation if possible. Once this issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as

  • CELLSNET-44242 - Support and usage of CustomXmlParts

Hi,

Thanks for using Aspose.Cells.

We have looked into this issue further and found that this feature is already present.
Please use the workbook.CustomDocumentProperties to add custom document properties.

Hi,

CustomDocumentProperties is not the same as CustomXmlParts. For one thing, the user is able to modify and delete CustomDocumentProperties, whereas the CustomXmlParts cannot be. I’m hesitant to allow users to break their document just because they were allowed to modify internal data. I’d prefer having support for CustomXmlParts.

Thank you.

Hi,

Thanks for your posting and using Aspose.Cells.

We have logged your comment in our database against this issue for re-investigation. We will look into it and update you. Once there is some news for you, we will let you know asap.

Hi,

Thanks for using Aspose.Cells.

Please use Workbook.ContentTypeProperties to add Custom Xml Part.

Please see the following code:

C#
Workbook workbook = new Workbook();
workbook.ContentTypeProperties.Add(“test”, “test”);
workbook.Save(path + “dest.xlsx”);

I need to be able to create and update the value from both Aspose.Cells and an Excel add-in. The Excel API does not have ContentTypeProperties on the Workbook class. Can you please post an example of using Excel to create the equivalent value?

Thank you

Hi,

Thanks for your posting and using Aspose.Cells.

What do you mean by Excel API or Excel Add-in? Will you please provide the code excel which meets your requirements using Excel API or Excel Add-in. It will help us mimic the same functionality using Aspose.Cells APIs.

Also, if you could provide some screenshots, it will be helpful for us as well as the sample project. Thanks for your cooperation.

Hi,

Thanks for explaining everything in detail and nicely as well as using Aspose.Cells.

We have logged your comment in our database for product team investigation. We will look into it and implement this feature if possible. Once there is some news for you, we will share it with you asap.

The issues you have found earlier (filed as CELLSNET-44242) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.