设置工作簿的公式计算模式通过JavaScript用C++
Contents
[
Hide
]
Microsoft Excel允许您设置公式计算模式,即公式计算的方式。有三种可能的值:
- 自动 - 每当有变更时重新计算,并且每次打开工作簿时。
- 自动除数据表外 - 每当有变更时重新计算,但是不包括数据表。
- 手动 - 仅当用户通过按F9或CTRL+ALT+F9明确请求时,或者保存工作簿时重新计算。
在Microsoft Excel中设置公式计算模式:
- 选择公式然后计算选项。
- 选择其中一个选项。
Aspose.Cells for JavaScript通过C++还允许您使用FormulaSettings.calculationMode模式属性设置公式计算模式。您可以将其赋值为具有以下值之一的CalcModeType枚举:
- 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>