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 the Formula parameter to embed formula in the smart marker field.
Using Formula parameter in Smart Marker field
The following sample code embeds the formula in the smart marker field named TestFormula and its data source name is MyDataSource, so the complete field with formula parameter looks like &=MyDataSource.TestFormula(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-.NET | |
//Create a datatable and add column named TestFormula | |
DataTable dt = new DataTable(); | |
dt.Columns.Add("TestFormula"); | |
//Create first row with formula (which basically concatenates three strings) | |
DataRow dr = dt.NewRow(); | |
dr["TestFormula"] = "=\"01-This \" & \"is \" & \"concatenation\""; | |
dt.Rows.Add(dr); | |
//Create second row like above | |
dr = dt.NewRow(); | |
dr["TestFormula"] = "=\"02-This \" & \"is \" & \"concatenation\""; | |
dt.Rows.Add(dr); | |
//Create third row like above | |
dr = dt.NewRow(); | |
dr["TestFormula"] = "=\"03-This \" & \"is \" & \"concatenation\""; | |
dt.Rows.Add(dr); | |
//Create fourth row like above | |
dr = dt.NewRow(); | |
dr["TestFormula"] = "=\"04-This \" & \"is \" & \"concatenation\""; | |
dt.Rows.Add(dr); | |
//Create fifth row like above | |
dr = dt.NewRow(); | |
dr["TestFormula"] = "=\"05-This \" & \"is \" & \"concatenation\""; | |
dt.Rows.Add(dr); | |
//Set the name of the data table | |
dt.TableName = "MyDataSource"; | |
//Create a workbook | |
Workbook wb = new Workbook(); | |
//Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
//Put the smart marker field with formula parameter in cell A1 | |
ws.Cells["A1"].PutValue("&=MyDataSource.TestFormula(Formula)"); | |
//Create workbook designer, set data source and process it | |
WorkbookDesigner wd = new WorkbookDesigner(wb); | |
wd.SetDataSource(dt); | |
wd.Process(); | |
//Save the workbook in xlsx format | |
wb.Save(outputDir + "outputUsingFormulaParameterInSmartMarkerField.xlsx"); |