Using Formula parameter in Smart Marker field

Possible Usage Scenarios

Sometimes, you want to embed formula in the smart marker field. This article describes how to make use of Formula parameter to embed formula in smart marker field.

Using Formula parameter in Smart Marker field

The following sample code embeds the formula in the smart marker variable named Test and its data source name is also Test, so the complete field with formula parameter looks like &=$Test(formula) and after the execution of the code, the final output Excel file will have formulas in cells from A1 till A5.

Sample Code

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Create array of strings that are actually Excel formulas
String str1 = "=\"01-This \" & \"is \" & \"concatenation\"";
String str2 = "=\"02-This \" & \"is \" & \"concatenation\"";
String str3 = "=\"03-This \" & \"is \" & \"concatenation\"";
String str4 = "=\"04-This \" & \"is \" & \"concatenation\"";
String str5 = "=\"05-This \" & \"is \" & \"concatenation\"";
String[] TestFormula = new String[]{str1, str2, str3, str4, str5};
//Create a workbook
Workbook wb = new Workbook();
//Access first worksheet
Worksheet ws = wb.getWorksheets().get(0);
//Put the smart marker field with formula parameter in cell A1
Cells cells = ws.getCells();
Cell cell = cells.get("A1");
cell.putValue("&=$Test(formula)");
//Create workbook designer, set data source and process it
WorkbookDesigner wd = new WorkbookDesigner(wb);
wd.setDataSource("Test", TestFormula);
wd.process();
//Save the workbook in xlsx format
wb.save(outDir + "outputUsingFormulaParameterInSmartMarkerField.xlsx");