Unterbrechen oder brechen Sie die Formelberechnung der Arbeitsmappe ab
Mögliche Nutzungsszenarien
Aspose.Cells bietet einen Mechanismus zum Unterbrechen oder Abbrechen der Formelberechnung der Arbeitsmappe mithilfe der Methode interrupt() derAbstractCalculationMonitor Klasse. Dies ist nützlich, wenn die Formelberechnung der Arbeitsmappe zu viel Zeit in Anspruch nimmt und Sie ihre Verarbeitung abbrechen möchten.
Unterbrechen oder brechen Sie die Formelberechnung der Arbeitsmappe ab
Der folgende Beispielcode implementiert dievorherBerechnen() Methode derAbstractCalculationMonitorKlasse. Innerhalb dieser Methode findet es den Zellennamen mithilfe von Zeilen- und Spaltenindexparametern. Wenn der Zellenname B8 ist, unterbricht es den Berechnungsprozess, indem es die Methode AbstractCalculationMonitor.interrupt() aufruft. Einmal die konkrete Klasse vonAbstractCalculationMonitorKlasse implementiert ist, wird ihre Instanz zugewiesenBerechnungsoptionen.BerechnungsmonitorEigentum. Endlich,Workbook.calculateFormula() wird durch Vorbeigehen aufgerufenBerechnungsoptionenals Parameter. Bitte sehen Sie sich … anBeispiel-Excel-Dateiinnerhalb des Codes sowie der Konsolenausgabe des unten angegebenen Codes als Referenz verwendet.
Beispielcode
// 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); | |
} |
Konsolenausgabe
0----1----3----D2
0----4----6----G5
0----7----1----B8