How to set AutoRecover property of Workbook with JavaScript via C++
Contents
[
Hide
]
You can use Aspose.Cells to set the AutoRecover property of the workbook. The default value of this property is true. When you set it false on a workbook, Microsoft Excel disables AutoRecover (Autosave) on that Excel file.
Aspose.Cells provides Workbook.autoRecover property to enable or disable this option.
The following code explains how to use Workbook.autoRecover property of the workbook. The code first reads the default value of this property which is true, then it sets it as false and saves the workbook. Then it reads the workbook again and reads the value of this property which is false at this time.
JavaScript code to set the AutoRecover property of Workbook
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example - AutoRecover</title>
</head>
<body>
<h1>AutoRecover Property 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, Worksheet, Cell, Utils } = 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 () => {
const resultDiv = document.getElementById('result');
resultDiv.innerHTML = '';
// Create workbook object
const workbook = new Workbook();
// Read AutoRecover property
const autoRecoverBefore = workbook.settings.autoRecover;
resultDiv.innerHTML += `<p>AutoRecover before: ${autoRecoverBefore}</p>`;
// Set AutoRecover property to false
workbook.settings.autoRecover = false;
// 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 output_out.xlsx';
// Read the saved workbook again from the saved data
const workbook2 = new Workbook(new Uint8Array(outputData));
// Read AutoRecover property
const autoRecoverAfter = workbook2.settings.autoRecover;
resultDiv.innerHTML += `<p>AutoRecover after reload: ${autoRecoverAfter}</p>`;
});
</script>
</html>
Output
AutoRecover: True
AutoRecover: False