EPPlus如何检查循环引用?

我正在使用EPPlus库build立一个excel文件,并想知道是否有一种方法使用这个库来检查公式中的循环引用?

我知道Microsoft Interop具有Range CircularReference {get; } ,但我试图避免使用它。

如果有一个循环引用,并且不允许它在计算选项中,则在尝试计算时将抛出exception。

顺便说一句,默认情况下循环引用抛出exception。 允许他们将属性更改为true。

您也可以计算整个工作表/工作簿。

用于检查单元格是否包含循环引用的示例代码:

//Assign Formula var cell = worksheet.Cells["A2"]; //Example Cell cell.Formula = "YourFormula"; //Initiate calculation option var calculateOptions = new ExcelCalculationOption(); calculateOptions.AllowCirculareReferences = false; bool isFormulaCircularReference = false; try { cell.Calculate(calculateOptions); } catch (CircularReferenceException ex) { //If there is a circular reference this exception will be thrown isFormulaCircularReference = true; }