How to check Frozen State without Excel using JavaScript via C++
Contents
[
Hide
]
Introduction
In this article, we will learn how to check the frozen state of an Excel worksheet programmatically. We can simply find whether the worksheet is frozen or split in MS Excel. But is there a way to find whether it is frozen or split with JavaScript? We can simply do it with Aspose.Cells for JavaScript via C++.
Are Window Panes Frozen
With Aspose.Cells for JavaScript via C++, we can check whether the window is frozen and how many rows and columns are locked.
Please use the Worksheet.paneState property to check the state of window panes and get locked rows and columns with the Worksheet.freezedPanes property.
- Construct Workbook to open the file.
- Check whether the worksheet is frozen.
- Get the locked rows and columns.
<!DOCTYPE html>
<html>
<head>
<title>Check Frozen Panes Example</title>
</head>
<body>
<h1>Check Frozen Panes 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, PaneStateType, 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 fileInput = document.getElementById('fileInput');
if (!fileInput.files.length) {
document.getElementById('result').innerHTML = '<p style="color: red;">Please select an Excel file.</p>';
return;
}
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
// Loading the workbook which contains frozen panes
const workbook = new Workbook(new Uint8Array(arrayBuffer));
const sheet = workbook.worksheets.get(0);
// Check whether worksheet is frozen.
const paneState = sheet.paneState;
if (paneState === PaneStateType.Frozen || paneState === PaneStateType.FrozenSplit) {
// Gets locked rows and columns.
const panes = sheet.freezedPanes;
let html = '<p style="color: green;">Worksheet has frozen panes. Details:</p><ul>';
panes.forEach((value) => {
const row = value[0];
const column = value[1];
const rows = value[2];
const columns = value[3];
html += `<li>row: ${row}, column: ${column}, rows: ${rows}, columns: ${columns}</li>`;
});
html += '</ul>';
document.getElementById('result').innerHTML = html;
} else {
document.getElementById('result').innerHTML = '<p>Worksheet is not frozen.</p>';
}
});
</script>
</html>