Setting Formula Calculation Mode of Workbook with JavaScript via C++
Contents
[
Hide
]
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 for JavaScript via C++ also allows you to set the Formula Calculation Mode using FormulaSettings.calculationMode mode property. You can assign it the CalcModeType enumeration which has one of the following values:
- CalcModeType.Automatic
- CalcModeType.AutomaticExceptTable
- CalcModeType.Manual
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example</title>
</head>
<body>
<h1>Aspose.Cells Example</h1>
<input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
<button id="runExample">Run Example</button>
<a id="downloadLink" style="display: none;">Download Result</a>
<div id="result"></div>
</body>
<script src="aspose.cells.js.min.js"></script>
<script type="text/javascript">
const { Workbook, SaveFormat } = AsposeCells;
AsposeCells.onReady({
license: "/lic/aspose.cells.enc",
fontPath: "/fonts/",
fontList: [
"arial.ttf",
"NotoSansSC-Regular.ttf"
]
}).then(() => {
console.log("Aspose.Cells initialized");
});
document.getElementById('runExample').addEventListener('click', async () => {
// Creating a workbook
const workbook = new Workbook();
// Set the Formula Calculation Mode to Manual
workbook.settings.formulaSettings.calculationMode = AsposeCells.CalcModeType.Manual;
// Save the workbook
const outputData = workbook.save(SaveFormat.Xlsx);
const blob = new Blob([outputData]);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'output_out.xlsx';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Excel File';
document.getElementById('result').innerHTML = '<p style="color: green;">Workbook created and saved successfully. Click the download link to get the file.</p>';
});
</script>
</html>