Vergleich und Migration mit JavaScript über C++
Contents
[
Hide
]
Vergleich zwischen .NET und JavaScript über C++
Beim Übergang von Aspose.Cells for .NET zu Aspose.Cells for JavaScript über C++ gibt es bestimmte Unterschiede hinsichtlich der Bibliotheksstruktur, Syntax und Funktionalität. Im Folgenden ist ein Vergleich, um diese Unterschiede zu verstehen.
1. Initialisierung
In .NET werden Objekte häufig mithilfe von Konstruktoren initialisiert. In JavaScript über C++ erstellt man Instanzen typischerweise mit dem new-Schlüsselwort, integriert in die JavaScript-Syntax:
<!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. Zugriff auf Arbeitsblätter
In .NET könnte der Code zum Zugriff auf ein Arbeitsblatt folgendermaßen aussehen: