在智能标记字段中使用Formula参数
Contents
[
Hide
]
可能的使用场景
有时,您想在智能标记字段中嵌入公式。本文介绍了如何使用Formula参数在智能标记字段中嵌入公式。
在智能标记变量名为Test及其数据源名称也为Test中嵌入公式的下面样本代码是这样子的 &=$Test(formula),在执行代码后,最终的输出Excel文件将在A1到A5单元格中具有公式。
下面的示例代码将在名为Test的智能标记变量中嵌入公式,其数据源名称也为Test,因此带有公式参数的完整字段看起来像**&=$Test(formula)**,执行代码后,最终输出的Excel文件中将在A1到A5单元格中包含公式。
示例代码
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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"); |