Smart MarkerフィールドでFormulaパラメータを使用する
Contents
[
Hide
]
可能な使用シナリオ
Smart Markerフィールドに数式を埋め込む場合があります。この記事では、Smart Markerフィールドで Formula パラメータを使用する方法について説明します。
Smart MarkerフィールドでFormulaパラメータを使用
次のサンプルコードは、データソース名が MyDataSource である Smart Marker フィールド TestFormula に数式を埋め込んでいます。コードの実行後、最終出力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-.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"); |