مقاطعة أو إلغاء حساب صيغة المصنف
سيناريوهات الاستخدام الممكنة
يوفر Aspose.Cells آلية لمقاطعة أو إلغاء حساب صيغة المصنف باستخدام طريقة المقاطعة () الخاصة بـAbstractCalculationMonitor صف دراسي. يكون هذا مفيدًا عندما يستغرق حساب صيغة المصنف وقتًا طويلاً وتريد إلغاء معالجته.
مقاطعة أو إلغاء حساب صيغة المصنف
نموذج التعليمات البرمجية التالي بتنفيذbeforeCalculate () طريقة الAbstractCalculationMonitorصف دراسي. داخل هذه الطريقة ، تجد اسم الخلية باستخدام معلمات فهرس الصفوف والعمود. إذا كان اسم الخلية هو B8 ، فإنه يقطع عملية الحساب عن طريق استدعاء طريقة AbstractCalculationMonitor.interrupt (). مرة واحدة ، فئة ملموسة منAbstractCalculationMonitorتم تنفيذ فئة ، تم تعيين مثيلها إلىCalculationOptions.CalculationMonitorخاصية. أخيراً،Workbook.calculateFormula () يسمى بالمرورخيارات الحسابكمعامل. الرجاء مراجعةنموذج لملف 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