I am implementing an AbstractCalculationMonitor. In overriding my beforeCalculate method I would like access to the Cell object - specifically the isErrorValue() method but really I want access to the whole Cell which is being calculated. Is this possible?
@cwedwards92 you can use the following implementation of AbstractCalculationMonitor
to access to the cell to calculate:
class MyCalculationMonitor : AbstractCalculationMonitor
{
private readonly Workbook _workbook;
public MyCalculationMonitor(Workbook wb)
{
_workbook = wb;
}
public override void BeforeCalculate(int sheetIndex, int rowIndex, int colIndex)
{
var cell = _workbook.Worksheets[sheetIndex].Cells[rowIndex, colIndex];
}
}
Workbook wb = new Workbook("C:\\Temp\\cells\\input.xlsx");
CalculationOptions opts = new CalculationOptions();
opts.CalculationMonitor = new MyCalculationMonitor(wb);
wb.CalculateFormula(opts);
@cwedwards92,
The java sample code as follows:
public class TestMonitor extends AbstractCalculationMonitor
{
private Workbook book;
public TestMonitor(Workbook wb)
{
book = wb;
}
@Override
public void beforeCalculate(int sheetIndex, int rowIndex, int colIndex)
{
Cell cell = book.getWorksheets().get(sheetIndex).getCells().get(rowIndex, colIndex);
System.out.println(cell.getName());
}
}
Workbook wb = new Workbook(filePath + "a.xlsx");
CalculationOptions opts = new CalculationOptions();
opts.setCalculationMonitor(new TestMonitor(wb));
wb.calculateFormula(opts);
1 Like
Hmm I was trying to avoid passing my workbook object into one of its own methods but maybe there’s no concern there. This definitely works, thank you for the quick response!
@cwedwards92,
I’m glad your issue has been solved. If you have any questions, please feel free to contact us.