انقطاع أو إلغاء حساب الصيغة لورقة العمل

سيناريوهات الاستخدام المحتملة

توفر Aspose.Cells آلية لإيقاف أو إلغاء عملية حساب الصيغ في دفتر العمل باستخدام طريقة interrupt() من الفئة AbstractCalculationMonitor. هذا مفيد عندما تستغرق عملية حساب الصيغ في دفتر عمل وقتًا طويلاً وترغب في إلغاء معالجتها.

إيقاف أو إلغاء حساب الصيغ في سجل العمل

يقوم الكود المثالي التالي بتنفيذ الأسلوب beforeCalculate() في فئة AbstractCalculationMonitor. داخل هذا الأسلوب ، يتم العثور على اسم الخلية باستخدام معلمتي فهرس الصف والعمود. إذا كان اسم الخلية هو B8 ، يقوم بإخلاء عملية الحساب عن طريق استدعاء الأسلوب AbstractCalculationMonitor.interrupt(). بمجرد تنفيذ فئة AbstractCalculationMonitor ، يتم تعيين مثيلها إلى CalculationOptions.CalculationMonitor أخيرًا ، يتم استدعاء Workbook.calculateFormula() عن طريق تمرير CalculationOptions كمعلمة. يرجى الرجوع إلى ملف Excel نموذجي المستخدم داخل الكود وإخراج وحدة التحكم في الكونسول للكود المعطى أدناه للرجوع إلى المرجع.

الكود المثالي

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java
//Implement calculation monitor class
class clsCalculationMonitor extends AbstractCalculationMonitor
{
public void beforeCalculate(int sheetIndex, int rowIndex, int colIndex)
{
//Find the cell name
String cellName = CellsHelper.cellIndexToName(rowIndex, colIndex);
//Print the sheet, row and column index as well as cell name
System.out.println(sheetIndex + "----" + rowIndex + "----" + colIndex + "----" + cellName);
//If cell name is B8, interrupt/cancel the formula calculation
if (cellName.equals("B8") == true)
{
this.interrupt("Interrupt/Cancel the formula calculation");
}//if
}//beforeCalculate
}//clsCalculationMonitor
//---------------------------------------------------------
//---------------------------------------------------------
public void Run() throws Exception
{
//Load the sample Excel file
Workbook wb = new Workbook(srcDir + "sampleCalculationMonitor.xlsx");
//Create calculation options and assign instance of calculation monitor class
CalculationOptions opts = new CalculationOptions();
opts.setCalculationMonitor(new clsCalculationMonitor());
//Calculate formula with calculation options
wb.calculateFormula(opts);
}

مخرجات الوحدة

0----1----3----D2

0----4----6----G5

0----7----1----B8