How to work with Web Extensions using Aspose.Words for Java

My team is also very interested in this. We have discovered that it is almost completely possible with the current CustomPart framework. The one thing that’s missing is the ability to set the parent reference. These methods are not publicly exposed by your API. In com.aspose.words.CustomPart, the methods appear to me as zzVX(String) and zzoD() that wrap member zz52. If I manually enter this data via debugging, the resulting docx file correctly embeds my apps for Office task pane. While a deepClone() of an existing instance also works, we’d rather not have to have a template docx but rather build the CustomPart ourselves. Here’s our code that performs the copy at this point:

Document withTaskPane = new Document(“c:\temp\BingOpen.docx”);

System.out.println(“Custom parts:”);

CustomPartCollection cpc = withTaskPane.getPackageCustomParts();

Document d = new Document();

CustomPartCollection emptyParts = d.getPackageCustomParts();

for (CustomPart cp:cpc) {

CustomPart newPart = new CustomPart();

newPart.setContentType(cp.getContentType());

newPart.setName(cp.getName());

newPart.setRelationshipType(cp.getRelationshipType());

newPart.isExternal(false);

String data = new String(cp.getData(), “UTF-8”);

newPart.setData(data.getBytes());

emptyParts.add(newPart);

}

d.save(“c:\temp\newDocTest.docx”);

Hi Adam,


Thanks for the details. Your request has been linked to the appropriate issue (WORDSNET-10593) and you will be notified as soon as “Support of Web Extensions” feature is supported. Sorry for the inconvenience.

Secondly, please clarify what do you mean by setting the parent reference. Also, please confirm what methods you would like to have in current API of CustomPart. Do you require public methods against the methods which appear as zzVX(String) and zzoD() and zz52.

Best regards,

Thank you for adding my details to the ticket!


My understanding of the code from looking at the behavior is that the variable zz52 indicates the parent container of the custompart. I could be wrong. If I debug through the code and manually update zz52 to contain the appropriate value, the document saves and opperates correctly. In my case, there are two custom parts. One is /word/webextensions/taskpanes.xml with zz52 set to “/” and the other is /word/webextensions/webextension1.xml with zz52 set to /word/webextensions/taskpanes.xml. Inspecting the Word document shows that the web extension is referenced by (or a child of) the taskpane and the taskpane is referenced by the document root. Yes, I believe that public methods against those which appear as zzVX(String) and zzoD() would solve the problem.

Hi Adam,


Thanks for your inquiry. I have logged this requirement in our issue tracking system as WORDSNET-11710. Our product team will further look into the details of this requirement and we will keep you updated on the status of this issue. We apologize for any inconvenience.

Best regards,

The issues you have found earlier (filed as WORDSNET-10593) have been fixed in this Aspose.Words for .NET 19.12 update and this Aspose.Words for Java 19.12 update.

@asinger

We would like to share with you that support of Web Extensions was added in Aspose.Words for Java 19.12. The document class provides a Document.WebExtensionTaskPanes property which returns a list of task pane add-ins.

Please read following article for more detail.
Work with Web Extensions

The following code example shows how to create task panes and add to web extension task panes.

Document doc = new Document();

TaskPane taskPane = new TaskPane();
doc.getWebExtensionTaskPanes().add(taskPane);

taskPane.setDockState(TaskPaneDockState.RIGHT);
taskPane.isVisible(true);
taskPane.setWidth(300);

taskPane.getWebExtension().getReference().setId("wa102923726");
taskPane.getWebExtension().getReference().setVersion("1.0.0.0");
taskPane.getWebExtension().getReference().setStoreType(WebExtensionStoreType.OMEX);
taskPane.getWebExtension().getReference().setStore("th-TH");
taskPane.getWebExtension().getProperties().add(new WebExtensionProperty("mailchimpCampaign", "mailchimpCampaign"));
taskPane.getWebExtension().getBindings().add(new WebExtensionBinding("UnnamedBinding_0_1506535429545", WebExtensionBindingType.TEXT, "194740422"));
        
doc.save(dataDir + "output.docx", SaveFormat.DOCX);