Setting Formula Calculation Mode of Workbook with Python.NET
Contents
[
Hide
]
Setting Formula Calculation Mode in Workbook
Microsoft Excel provides three formula calculation modes:
- Automatic: Recalculates formulas on every change and workbook open
- Automatic except for data tables: Recalculates formulas except data tables on changes
- Manual: Only recalculates when user requests (F9/CTRL+ALT+F9) or during save
Setting Calculation Mode with Aspose.Cells
Aspose.Cells for Python via .NET provides the formula_settings configuration through the Workbook.settings property. Use the calculation_mode attribute to control calculation behavior.
Available modes via CalcModeType enum:
AUTOMATIC
AUTOMATIC_EXCEPT_TABLE
MANUAL
Implementation Steps:
- Load existing workbook or create new instance
- Access workbook settings
- Set calculation mode using
formula_settings.calculation_mode
- Save modified workbook
from aspose.cells import Workbook, CalcModeType
# Load source workbook
workbook = Workbook("source.xlsx")
# Configure manual calculation mode
workbook.settings.formula_settings.calculation_mode = CalcModeType.MANUAL
# Save modified workbook
workbook.save("output.xlsx")
import os
from aspose.cells import Workbook, CalcModeType, SaveFormat
# For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
# The path to the documents directory.
current_dir = os.path.dirname(os.path.abspath(__file__))
data_dir = os.path.join(current_dir, "data")
# Create a workbook
workbook = Workbook()
# Set the Formula Calculation Mode to Manual
workbook.settings.formula_settings.calculation_mode = CalcModeType.MANUAL
# Save the workbook
output_path = os.path.join(data_dir, "output_out.xlsx")
workbook.save(output_path, SaveFormat.XLSX)