Utilizzando il parametro Formula nel campo Smart Marker

Possibili scenari di utilizzo

A volte, vuoi incorporare la formula nel campo del marcatore intelligente. Questo articolo descrive come utilizzare ilFormulaparametro per incorporare la formula nel campo del marcatore intelligente.

Utilizzando il parametro Formula nel campo Smart Marker

Il seguente codice di esempio incorpora la formula nel campo dell’indicatore intelligente denominato TestFormula e il nome dell’origine dati è MyDataSource, quindi il campo completo con il parametro della formula è simile a &=MyDataSource.TestFormula(formula) e dopo l’esecuzione del codice, ilfile Excel di output finale avrà formule nelle celle da A1 a A5.

Codice d’esempio

// 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");