Schermo diviso del foglio di lavoro di Excel con JavaScript tramite C++
Introduzione
In questo articolo, impareremo come visualizzare alcune righe e/o colonne in pannelli separati dividendo il foglio di lavoro in due o quattro parti. Quando si lavora con grandi set di dati, è necessario vedere alcune aree del stesso foglio contemporaneamente per confrontare diverse sottosezioni di dati. La funzione di divisione dello schermo può soddisfare le tue esigenze.
Come dividere lo schermo in Excel
Per suddividere un foglio di lavoro in due o quattro parti, procedi come segue:
- Seleziona la riga/colonna/cella prima della quale desideri posizionare la suddivisione.
- Sulla scheda Visualizza, nel gruppo Finestre, fai clic sul pulsante Suddivisione.

Suddividi il foglio di lavoro verticalmente sulle colonne
Per separare due aree del foglio di calcolo verticalmente, seleziona la colonna a destra della colonna in cui desideri che appaia la suddivisione e fai clic sul pulsante Suddivisione in Excel.
È facile dividere verticalmente il foglio di lavoro in colonne programmaticamente con Aspose.Cells for JavaScript tramite C++, basta selezionare una cella nella riga superiore come cella attiva, quindi dividere con il metodo Worksheet.split().
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example</title>
</head>
<body>
<h1>Set Active Cell and Split Worksheet 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;
const readyPromise = 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;
}
await readyPromise;
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
// Instantiate a new Workbook from the uploaded file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Access the first worksheet
const sheet = workbook.worksheets.get(0);
// Sets C1 cell in the top row as the active cell.
sheet.activeCell = "C1";
// Split worksheet vertically on columns
sheet.split();
// Save the modified workbook and prepare download link
const outputData = workbook.save(SaveFormat.Xlsx);
const blob = new Blob([outputData]);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'output.xlsx';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Modified Excel File';
document.getElementById('result').innerHTML = '<p style="color: green;">Worksheet updated successfully! Click the download link to get the modified file.</p>';
});
</script>
</html>
Suddividi il foglio di lavoro orizzontalmente sulle righe
Per separare la finestra di Excel orizzontalmente, seleziona la riga sotto la riga in cui desideri che avvenga la suddivisione in Excel.
È facile dividere orizzontalmente il foglio di lavoro in righe programmaticamente con Aspose.Cells for JavaScript tramite C++, basta selezionare una cella nella colonna di sinistra come cella attiva, quindi dividere con il metodo Worksheet.split().
<!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, 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 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();
// Instantiating a Workbook object from the uploaded file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Accessing the first worksheet in the Excel file
const sheet = workbook.worksheets.get(0);
// Sets A6 cell in the left column as the active cell.
sheet.activeCell = "A6";
// Split worksheet horizontally on rows
sheet.split();
// Saving the modified Excel file
const outputData = workbook.save(SaveFormat.Xlsx);
const blob = new Blob([outputData], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' });
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'dest.xlsx';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Modified Excel File';
document.getElementById('result').innerHTML = '<p style="color: green;">Operation completed successfully! Click the download link to get the modified file.</p>';
});
</script>
</html>
Dividi il foglio di lavoro in quattro parti.
Per visualizzare contemporaneamente quattro diverse sezioni dello stesso foglio di lavoro, dividi lo schermo sia verticalmente che orizzontalmente in Excel.
È facile dividere verticalmente il foglio di lavoro in colonne programmaticamente con Aspose.Cells for JavaScript tramite C++, basta selezionare una cella che non si trovi nella prima riga e nella prima colonna come cella attiva, quindi dividere con il metodo Worksheet.split().
<!DOCTYPE html>
<html>
<head>
<title>Set Active Cell and Split Worksheet Example</title>
</head>
<body>
<h1>Set Active Cell and Split Worksheet 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 () => {
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();
// Instantiate a new Workbook from the uploaded file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Access the first worksheet
const sheet = workbook.worksheets.get(0);
// Sets E6 cell as the active cell.
sheet.activeCell = "E6";
// Split worksheet into four parts
sheet.split();
// Save the modified workbook and provide a download link
const outputData = workbook.save(SaveFormat.Xlsx);
const blob = new Blob([outputData]);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'output.xlsx';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Modified Excel File';
document.getElementById('result').innerHTML = '<p style="color: green;">Worksheet updated successfully. Click the download link to get the modified file.</p>';
});
</script>
</html>
Come rimuovere la divisione
Per rimuovere la divisione del foglio di lavoro, basta fare clic sul pulsante Dividi di nuovo.
Aspose.Cells for JavaScript tramite C++ fornisce un metodo Worksheet.removeSplit() per rimuovere l’impostazione di divisione.
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Split Worksheet Example</title>
</head>
<body>
<h1>Split Worksheet 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 () => {
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();
// Instantiate a new Workbook from uploaded file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
const sheet = workbook.worksheets.get(0);
// Remove split and then split worksheet into four parts
sheet.removeSplit();
sheet.split();
// Save the modified workbook and provide download link
const outputData = workbook.save(SaveFormat.Xlsx);
const blob = new Blob([outputData]);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'output.xlsx';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Modified Excel File';
document.getElementById('result').innerHTML = '<p style="color: green;">Worksheet split operation completed successfully! Click the download link to get the modified file.</p>';
});
</script>
</html>