Setting Formula Calculation Mode of Workbook with C++
Microsoft Excel allows you to set the formula calculation mode, that is, the way formulas are calculated. There are three possible values:
- Automatic - recalculate whenever something is changed, and every time a workbook is opened.
- Automatic except for data tables - recalculate whenever something is changed, but leaving out data tables.
- Manual - recalculate only when the user explicitly requests it by pressing F9 or CTRL+ALT+F9, or when the workbook is saved.
To set the formula calculation mode in Microsoft Excel:
- Select Formulas and then Calculation Options.
- Select one of the options.
Aspose.Cells also allows you to set the Formula Calculation Mode using FormulaSettings.GetCalculationMode() mode property. You can assign it the CalcModeType enumeration which has one of the following values:
- CalcModeType::Automatic
- CalcModeType::AutomaticExceptTable
- CalcModeType::Manual
#include <iostream>
#include "Aspose.Cells.h"
using namespace Aspose::Cells;
int main()
{
Aspose::Cells::Startup();
// Source directory path
U16String srcDir(u"..\\Data\\01_SourceDirectory\\");
// Output directory path
U16String outDir(u"..\\Data\\02_OutputDirectory\\");
// Path of output excel file
U16String outputFilePath = outDir + u"output_out.xlsx";
// Create a workbook
Workbook workbook;
// Set the Formula Calculation Mode to Manual
workbook.GetSettings().GetFormulaSettings().SetCalculationMode(CalcModeType::Manual);
// Save the workbook
workbook.Save(outputFilePath, SaveFormat::Xlsx);
std::cout << "Workbook saved successfully with manual calculation mode!" << std::endl;
Aspose::Cells::Cleanup();
}