循環参照の検出
Contents
[
Hide
]
序章
ワークブックには循環参照が含まれている可能性があり、循環参照が存在するかどうかを検出する必要がある場合があります。
循環参照の検出の背後にある概念
循環参照は、式が計算されたときにのみ検出できます。これは、1 つの式の参照は通常、他の部分または他の式の計算結果に依存するためです。そのため、式の計算の過程でこの要件 (循環参照を含むセルを収集する) に対応する新しい API を提供します。
計算セル計算中の 1 つのセルに関する関連データの計算を表します
AbstractCalculationMonitor.OnCircular(IEnumerator circleCellsData)循環参照に遭遇すると、数式計算エンジンによって呼び出されます。列挙子の要素は計算セル つの円内のすべてのセルを表すオブジェクト。返される値は、この呼び出しの後に数式エンジンがこれらのセルを循環的に計算する必要があるかどうかを示します。
ユーザーは、これらの循環参照を次の実装で収集できます。AbstractCalculationMonitor.OnCircular()方法。
ソース サンプル ファイルは、次のリンクからダウンロードできます。
This file contains 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 | |
LoadOptions LoadOptions = new LoadOptions(); | |
Workbook objWB = new Workbook(sourceDir + "Circular Formulas.xls", LoadOptions); | |
objWB.Settings.FormulaSettings.EnableIterativeCalculation = true; | |
CalculationOptions copts = new CalculationOptions(); | |
CircularMonitor cm = new CircularMonitor(); | |
copts.CalculationMonitor = cm; | |
objWB.CalculateFormula(copts); | |
int lngCircularRef = cm.circulars.Count; | |
Console.WriteLine("Circular References found - " + lngCircularRef); |
の定義円形モニターから派生したクラスAbstractCalculationMonitorクラスは次のとおりです。
This file contains 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 | |
public class CircularMonitor : AbstractCalculationMonitor | |
{ | |
public ArrayList circulars = new ArrayList(); | |
public ArrayList Circulars { get { return circulars; } } | |
public override bool OnCircular(IEnumerator circularCellsData) | |
{ | |
CalculationCell cc = null; | |
ArrayList cur = new ArrayList(); | |
while (circularCellsData.MoveNext()) | |
{ | |
cc = (CalculationCell)circularCellsData.Current; | |
cur.Add(cc.Worksheet.Name + "!" + CellsHelper.CellIndexToName(cc.CellRow, cc.CellColumn)); | |
} | |
circulars.Add(cur); | |
return true; | |
} | |
} |