Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Normally, we recommend that users call Workbook.CalculateFormula() once and then get the calculated values of the individual cells. But sometimes, users do not want to calculate the entire workbook; they just want to calculate a single cell. Aspose.Cells provides the CalculationOptions.GetRecursive() property, which you can set to false, and it will decrease the calculation time of individual cells significantly. When the recursive property is set to true, all dependent cells are recalculated on each call. When it is false, dependent cells are calculated only once and are not recalculated on subsequent calls.
The following sample code illustrates the usage of the CalculationOptions.GetRecursive() property. Please execute this code with the given sample excel file and check its console output. You will find that setting the recursive property to false has decreased the calculation time significantly. Please also read the comments for a better understanding of this property.
#include <iostream>
#include <chrono>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
void TestCalcTimeRecursive(bool isRecursive) {
Workbook* workbook = new Workbook();
CalculationOptions options;
options.SetRecursive(isRecursive);
auto start = std::chrono::high_resolution_clock::now();
workbook.CalculateFormula(&options);
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
std::cout << "Time (recursive=" << isRecursive << "): " << duration << " ms" << std::endl;
delete workbook;
}
int main() {
Aspose::Cells::Startup();
TestCalcTimeRecursive(true);
TestCalcTimeRecursive(false);
Aspose::Cells::Cleanup();
return 0;
}
#include <iostream>
#include <chrono>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
using namespace std::chrono;
void TestCalcTimeRecursive(bool rec) {
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
Workbook wb(srcDir + u"sample.xlsx");
Worksheet ws = wb.GetWorksheets().Get(0);
CalculationOptions opts;
opts.SetRecursive(rec);
auto start = high_resolution_clock::now();
for (int i = 0; i < 1000000; i++) {
ws.GetCells().Get(u"A1").Calculate(opts);
}
auto stop = high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stop - start);
long estimatedTime = duration.count() / 1000;
std::cout << "Recursive " << rec << ": " << estimatedTime << " seconds" << std::endl;
}
int main() {
Aspose::Cells::Startup();
TestCalcTimeRecursive(true);
TestCalcTimeRecursive(false);
Aspose::Cells::Cleanup();
return 0;
}
This is the console output of the above sample code when executed with the given sample excel file on our machine. Please note that your output may differ, but the elapsed time after setting the recursive property to false will always be less than when it is set to true.
Recursive True: 96 seconds
Recursive False: 42 seconds Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.