[]
Provides information about the cell currently being calculated, including its containing worksheet, row index, and column index. This interface is typically used in custom function evaluation logic to determine where the calculation is occurring.
CustomFunction function = new CustomFunction("CELLPOS", FunctionValueType.Text) {
public Object evaluate(Object[] arguments, ICalcContext context) {
IWorksheet sheet = context.getWorksheet();
int row = context.getRow();
int column = context.getColumn();
return sheet.getName() + "!" + row + "," + column;
}
};
Workbook.AddCustomFunction(function);
worksheet.getRange("B2").setFormula("=CELLPOS()");
Object cellPosition = worksheet.getRange("B2").getValue();
intintgetRow()Use this method in a custom function to access the worksheet that contains the cell whose formula is being evaluated.
CustomFunction function = new CustomFunction("CAPTURESHEET", FunctionValueType.Text) {
public Object evaluate(Object[] arguments, ICalcContext context) {
IWorksheet sheet = context.getWorksheet();
return sheet.getName();
}
};
Workbook.AddCustomFunction(function);
worksheet.getRange("B2").setFormula("=CAPTURESHEET()");
Object sheetName = worksheet.getRange("B2").getValue();
Use this method in a custom function to identify the zero-based row position of the cell whose formula is currently being evaluated.
CustomFunction function = new CustomFunction("CAPTUREROW", FunctionValueType.Number) {
public Object evaluate(Object[] arguments, ICalcContext context) {
int row = context.getRow();
return (double) row;
}
};
Workbook.AddCustomFunction(function);
worksheet.getRange("C3").setFormula("=CAPTUREROW()");
Object row = worksheet.getRange("C3").getValue();
Use this method in a custom function to identify the zero-based column position of the cell whose formula is currently being evaluated.
CustomFunction function = new CustomFunction("CAPTURECOLUMN", FunctionValueType.Number) {
public Object evaluate(Object[] arguments, ICalcContext context) {
int column = context.getColumn();
return (double) column;
}
};
Workbook.AddCustomFunction(function);
worksheet.getRange("D4").setFormula("=CAPTURECOLUMN()");
Object column = worksheet.getRange("D4").getValue();