AbstractCalculationEngineを使用して値の範囲を返す
Contents
[
Hide
]
Aspose.Cellsは、Microsoft Excelの組み込み関数としてサポートされていないユーザー定義またはカスタム関数を実装するために使用されるAbstractCalculationEngineクラスを提供します。
この記事では、AbstractCalculationEngineから値の範囲を返す方法について説明します。
次のコードは、AbstractCalculationEngine クラスの使用をデモンストレーションし、そのメソッドを通じて値の範囲を返します。
関数CalculateCustomFunctionを持つクラスを作成します。このクラスではAbstractCalculationEngineを実装します。
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 | |
public class CustomFunctionStaticValue : AbstractCalculationEngine | |
{ | |
public override void Calculate(CalculationData data) | |
{ | |
data.CalculatedValue = new object[][] { | |
new object[]{new DateTime(2015, 6, 12, 10, 6, 30), 2}, | |
new object[]{3.0, "Test"} | |
}; | |
} | |
} |
上記の関数をプログラムで使用する
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 | |
// The path to the documents directory. | |
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
// Create workbook | |
Workbook workbook = new Workbook(); | |
Cells cells = workbook.Worksheets[0].Cells; | |
// Set formula | |
Cell cell = cells[0, 0]; | |
cell.SetArrayFormula("=MYFUNC()", 2, 2); | |
Style style = cell.GetStyle(); | |
style.Number = 14; | |
cell.SetStyle(style); | |
// Set calculation options for formula | |
CalculationOptions calculationOptions = new CalculationOptions(); | |
calculationOptions.CustomEngine = new CustomFunctionStaticValue(); | |
workbook.CalculateFormula(calculationOptions); | |
// Save to xlsx by setting the calc mode to manual | |
workbook.Settings.FormulaSettings.CalculationMode = CalcModeType.Manual; | |
workbook.Save(dataDir + "output_out.xlsx"); | |
// Save to pdf | |
workbook.Save(dataDir + "output_out.pdf"); |