العمل مع محرك الحساب المخصص
تنفيذ محرك الحساب المخصص
Aspose.Cells.Gridweb لديه محرك حساب قوي يمكنه حساب جميع صيغ Excel Microsoft تقريبًا. على الرغم من ذلك ، فإنه يسمح لك أيضًا بتوسيع محرك الحساب الافتراضي الذي يوفر لك قدرًا أكبر من القوة والمرونة.
يتم استخدام الخصائص والفئات التالية في تنفيذ هذه الميزة.
- [GridAbstractCalculationEngine] (https://reference.aspose.com/cells/net/aspose.cells.gridweb.data/gridabstractcalculationengine)
- [GridCalculationData] (https://reference.aspose.com/cells/net/aspose.cells.gridweb.data/gridcalculationdata)
تقوم التعليمات البرمجية التالية بتنفيذ محرك الحساب المخصص. يقوم بتنفيذ الواجهة**[GridAbstractCalculationEngine] (https://reference.aspose.com/cells/net/aspose.cells.gridweb.data/gridabstractcalculationengine)** الذي يحتوي على**[حساب (بيانات GridCalculationData)] (https://reference.aspose.com/cells/net/aspose.cells.gridweb.data/gridabstractcalculationengine/methods/calculate)** طريقة. يتم استدعاء هذه الطريقة مقابل جميع الصيغ الخاصة بك. داخل هذه الطريقة ، نلتقط ملف**MYTESTFUNC** الصيغة وضربها في 2 لقيمة المعلمة الأولى.
عينة البرمجة
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET | |
private class CustomEngineSimple : GridAbstractCalculationEngine | |
{ | |
public override void Calculate(GridCalculationData data) | |
{ | |
if (!"MYTESTFUNC".Equals(data.FunctionName.ToUpper())) | |
{ | |
return; | |
} | |
data.CalculatedValue = (decimal)(2.0 * (double)data.GetParamValue(0)); | |
} | |
} | |
protected void Page_Load(object sender, EventArgs e) | |
{ | |
// If first visit this page clear GridWeb1 and load data | |
if (!IsPostBack && !GridWeb1.IsPostBack) | |
{ | |
CustomEngineSimple ce = new CustomEngineSimple(); | |
GridWeb1.CustomCalculationEngine = ce; | |
GridWorksheet sheet = GridWeb1.ActiveSheet; | |
GridCell cell = sheet.Cells["A1"]; | |
cell.Formula = "=MYTESTFUNC(3.0)"; | |
cell = sheet.Cells["A2"]; | |
cell.PutValue("hello"); | |
cell = sheet.Cells["B1"]; | |
cell.PutValue(1); | |
cell = sheet.Cells["B2"]; | |
cell.PutValue(2); | |
cell = sheet.Cells["B3"]; | |
cell.PutValue(3); | |
cell = sheet.Cells["A3"]; | |
cell.Formula = "=SUM(B1:B3)"; | |
GridWeb1.CalculateFormula(); | |
sheet.ActiveCell = "A4"; | |
} | |
} | |