Aspose::Cells::Startup(); //Implement AbstractCalculationEngine interface class CustomFunction2 : public AbstractCalculationEngine { public: int stage = 0; public: void Calculate(CalculationData& data) { if (stage == 0) { data.SetCalculatedValue(0); return; } U16String s = data.GetFunctionName(); if (u"crow" == s) { data.SetCalculatedValue(data.GetParamValue(0)); } else if (u"crow2" == s) { data.SetCalculatedValue(data.GetCellRow() + 1); } } }; //Create workbook Workbook wb(u"sample-file.xlsx"); Cells cells = wb.GetWorksheets().Get(0).GetCells(); Cells cells2 = wb.GetWorksheets().Get(1).GetCells(); U16String expectedValue = u"2"; if (expectedValue != cells.Get(u"B2").GetStringValue()) { std::cout << "Start test: The value of cell B2 is not 2." << std::endl; } cells.Get(u"A2").PutValue(2); cells.Get(u"A3").PutValue(3); // Calcualting Formulas CustomFunction2* resolver1 = new CustomFunction2(); resolver1->stage = 0; CalculationOptions opt1; opt1.SetCustomEngine(resolver1); wb.CalculateFormula(opt1); cells2.InsertRows(1, 9, true); Range range = cells2.CreateRange(1, 0, 9, cells2.GetMaxColumn() + 1); Range source = cells2.CreateRange(0, 0, 1, cells2.GetMaxColumn() + 1); PasteOptions options; options.SetPasteType(PasteType::All); range.Copy(source, options); // Calcualting Formulas CustomFunction2* resolver2 = new CustomFunction2(); resolver2->stage = 1; CalculationOptions opt2; opt2.SetCustomEngine(resolver2); wb.CalculateFormula(opt2); if (expectedValue == cells.Get(u"B2").GetStringValue()) { std::cout << "End test: The value of cell B2 is 2." << std::endl; } delete resolver1; delete resolver2; Aspose::Cells::Cleanup();