Create, Modify VBA Macros in Word Documents within Android

Today, I will highlight the major features introduced in the Aspose.Words for Android via Java 19.9 release:

Create and Modify VBA Macros in Word Documents

The following code example demonstrates as to how to modify VBA Macros in Word document programmatically by using the VbaModule.setSourceCode() property of Aspose.Words for Android via Java API.

Document doc = new Document(dataDir + "test.docm");
VbaProject project = doc.getVbaProject();
String newSourceCode = "Test change source code";
// Choose a module, and set a new source code.
project.getModules().get(0).setSourceCode(newSourceCode);

Create Repeating Section Content Controls in Word Document

TIP

You may want to check out Aspose FREE macro removal web app.

The repeating section content control allows repeating the content contained within it. Using Aspose.Words for Android via Java, the structured document tag nodes of the repeating section and repeating section item types can be created and for this purpose, SdtType enumeration type provides REPEATING_SECTION_ITEM member. The following code example demonstrates how to Bind a Repeating Section Content Control in Word Document to a Table.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
CustomXmlPart xmlPart = doc.getCustomXmlParts().add("Books",
"<books><book><title>Everyday Italian</title><author>Giada De Laurentiis</author></book>" +
"<book><title>Harry Potter</title><author>J K. Rowling</author></book>" +
"<book><title>Learning XML</title><author>Erik T. Ray</author></book></books>");
Table table = builder.startTable();
builder.insertCell();
builder.write("Title");
builder.insertCell();
builder.write("Author");
builder.endRow();
builder.endTable();
StructuredDocumentTag repeatingSectionSdt =
new StructuredDocumentTag(doc, SdtType.REPEATING_SECTION, MarkupLevel.ROW);
repeatingSectionSdt.getXmlMapping().setMapping(xmlPart, "/books[1]/book", "");
table.appendChild(repeatingSectionSdt);
StructuredDocumentTag repeatingSectionItemSdt =
new StructuredDocumentTag(doc, SdtType.REPEATING_SECTION_ITEM, MarkupLevel.ROW);
repeatingSectionSdt.appendChild(repeatingSectionItemSdt);
Row row = new Row(doc);
repeatingSectionItemSdt.appendChild(row);
StructuredDocumentTag titleSdt =
new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.CELL);
titleSdt.getXmlMapping().setMapping(xmlPart, "/books[1]/book[1]/title[1]", "");
row.appendChild(titleSdt);
StructuredDocumentTag authorSdt =
new StructuredDocumentTag(doc, SdtType.PLAIN_TEXT, MarkupLevel.CELL);
authorSdt.getXmlMapping().setMapping(xmlPart, "/books[1]/book[1]/author[1]", "");
row.appendChild(authorSdt);
doc.save(dataDir + "Document.docx");

LINQ Reporting using XML, JSON, and CSV Data Sources

The LINQ Reporting engine of ‘Aspose.Words for Android via Java’ now enables you to reference business objects of your application in report templates. We have added XmlDataSource, JsonDataSource, and CsvDataSource classes in this release to use XML, JSON, and CSV as data sources to generate reports using LINQ Reporting. Please read the following articles for complete detail of this feature.

Link Custom Document Property to Bookmark

‘Aspose.Words for Android via Java’ API now provides a method CustomDocumentProperties.addLinkToContent(String, String) to create a new ‘linked to content’ custom document property which returns the newly created property object or null if the link source is invalid. The following code example demonstrates how to Configure the Link to a Content Custom Property.

Document doc = new Document(dataDir + "test.docx");
// Retrieve a list of all custom document properties from the file.
CustomDocumentProperties customProperties = doc.getCustomDocumentProperties();
// Add linked to content property.
DocumentProperty customProperty = customProperties.addLinkToContent("PropertyName", "BookmarkName");
// Also, accessing the custom document property can be performed by using the property name.
customProperty = customProperties.get("PropertyName");
// Check whether the property is linked to content.
boolean isLinkedToContent = customProperty.isLinkToContent();
// Get the source of the property.
String source = customProperty.getLinkSource();
// Get the value of the property.
String value = customProperty.getValue().toString();

See also Useful Links

Keeping the Aspose tradition, you are welcome to shape the upcoming releases of ‘Aspose.Words for Android via Java’ API by posting your suggestions and concerns in the Aspose.Words for Android via Java Support Forum.