Filtrare il tipo di dati durante il caricamento del workbook da un file modello con JavaScript via C++
Contents
[
Hide
]
A volte si desidera specificare quale tipo di dati dovrebbe essere caricato quando si crea il workbook dal file modello. Filtrare i dati caricati può migliorare le prestazioni per scopi specifici, specialmente utilizzando LightCells APIs. Utilizza la proprietà LoadOptions.loadFilter per questo scopo.
Il seguente esempio carica soltanto oggetti forma durante il caricamento del workbook dal file modello, che si può scaricare dal link fornito. Il seguente screenshot mostra il contenuto del file modello e spiega anche che i dati di colore rosso e sfondo giallo non saranno caricati perché la proprietà LoadOptions.loadFilter è stata impostata su Shape

Lo screenshot seguente mostra il PDF di output che è possibile scaricare dal link fornito. Qui si può vedere che i dati di colore rosso e sfondo giallo non sono presenti ma ci sono tutte le forme.

<!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, LoadOptions, LoadFormat, LoadFilter, LoadDataFilterOptions, 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();
// Set the load options, we only want to load shapes and do not want to load data
const loadOptions = new LoadOptions(LoadFormat.Xlsx);
loadOptions.loadFilter = new LoadFilter(LoadDataFilterOptions.All & ~LoadDataFilterOptions.Chart);
// Create workbook object from uploaded excel file using load options
const workbook = new Workbook(new Uint8Array(arrayBuffer), loadOptions);
// Save the output in pdf format
const outputData = workbook.save(SaveFormat.Pdf);
const blob = new Blob([outputData], { type: 'application/pdf' });
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'sampleFilterChars_out.pdf';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Result PDF';
document.getElementById('result').innerHTML = '<p style="color: green;">Operation completed successfully! Click the download link to get the PDF file.</p>';
});
</script>
</html>