Impostare la modalità di calcolo delle formule del Workbook con Python.NET
Contents
[
Hide
]
Impostare la modalità di calcolo delle formule nel Workbook
Microsoft Excel fornisce tre modalità di calcolo delle formule:
- Automatico: Ricalcola le formule ad ogni modifica e all’apertura del workbook
- Automatico tranne che per le tabelle di dati: Ricalcola le formule tranne le tabelle di dati durante le modifiche
- Manuale: Ricalcola solo quando l’utente lo richiede (F9/CTRL+ALT+F9) o durante il salvataggio
Impostare la modalità di calcolo con Aspose.Cells
Aspose.Cells per Python via .NET fornisce la configurazione formula_settings tramite la proprietà Workbook.settings. Usa l’attributo calculation_mode per controllare il comportamento del calcolo.
Modalità disponibili tramite enum CalcModeType:
AUTOMATIC
AUTOMATIC_EXCEPT_TABLE
MANUAL
Passaggi di implementazione:
- Caricare il workbook esistente o crearne uno nuovo
- Accedere alle impostazioni del workbook
- Impostare la modalità di calcolo usando
formula_settings.calculation_mode
- Salvare il workbook modificato
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)