GridWeb'de Özel İşlevleri Hesaplayın
Contents
[
Hide
]
Olası Kullanım Senaryoları
Aspose.Cells.GridWeb, GridWeb.CustomCalculationEngine özelliğiyle özel işlevlerin hesaplanmasını destekler. Bu özellik, GridAbstractCalculationEngine arabiriminin örneğini alır. Lütfen GridAbstractCalculationEngine arayüzünü uygulayın ve özel fonksiyonlarınızı kendi mantığınızla hesaplayın.
GridWeb’de Özel İşlevleri Hesaplayın
Aşağıdaki örnek kod, B3 hücresine MYTESTFUNC() adlı özel bir işlev ekler. Daha sonra GridAbstractCalculationEngine arayüzünü implemente ederek bu fonksiyonun değerini hesaplıyoruz. MYTESTFUNC() parametresini 2 ile çarpacak ve sonucu verecek şekilde hesaplıyoruz. Yani parametresi 9 ise, 2*9 = 18 döndürür.
Basit kod
This file contains hidden or 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 | |
private class GridWebCustomCalculationEngine : GridAbstractCalculationEngine | |
{ | |
public override void Calculate(GridCalculationData data) | |
{ | |
// Calculate MYTESTFUNC() with your own logic. i.e Multiply MYTESTFUNC() parameter with 2 so MYTESTFUNC(3.0) = 6 | |
if ("MYTESTFUNC".Equals(data.FunctionName.ToUpper())) | |
{ | |
data.CalculatedValue = (decimal)(2.0 * (double)data.GetParamValue(0)); | |
} | |
} | |
} | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
if (Page.IsPostBack == false && GridWeb1.IsPostBack == false) | |
{ | |
// Assign your own custom calculation engine to GridWeb | |
GridWeb1.CustomCalculationEngine = new GridWebCustomCalculationEngine(); | |
// Access the active worksheet and add your custom function in cell B3 | |
GridWorksheet sheet = GridWeb1.ActiveSheet; | |
GridCell cell = sheet.Cells["B3"]; | |
cell.Formula = "=MYTESTFUNC(9.0)"; | |
// Calculate the GridWeb formula | |
GridWeb1.CalculateFormula(); | |
} | |
} |