Comparazione e Migrazione con JavaScript tramite C++
Contents
[
Hide
]
Confronto tra .NET e JavaScript tramite C++
Quando si passa da Aspose.Cells for .NET a Aspose.Cells for JavaScript tramite C++, ci sono alcune differenze da considerare in termini di struttura della libreria, sintassi e funzionalità. Di seguito una comparazione per aiutarti a comprendere queste differenze.
1. Inizializzazione
In .NET, gli oggetti sono spesso inizializzati usando costruttori. In JavaScript tramite C++, si creano tipicamente istanze usando la parola chiave new, integrata nella sintassi JavaScript:
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example</title>
</head>
<body>
<h1>Aspose.Cells Workbook Creation Example</h1>
<input type="file" id="fileInput" accept=".xls,.xlsx,.csv" />
<button id="runExample">Create Workbook (or load selected file)</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');
let workbook;
if (fileInput.files.length) {
const file = fileInput.files[0];
const arrayBuffer = await file.arrayBuffer();
workbook = new Workbook(new Uint8Array(arrayBuffer));
document.getElementById('result').innerHTML = '<p style="color: green;">Loaded workbook from selected file.</p>';
} else {
workbook = new Workbook();
document.getElementById('result').innerHTML = '<p style="color: green;">Created a new empty workbook.</p>';
}
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 Excel File';
});
</script>
</html>
2. Accesso ai Fogli di lavoro
In .NET, potresti vedere un codice come questo per accedere a un foglio di lavoro: