Comparison and Migration with JavaScript via C++
Contents
[
Hide
]
Comparison Between .NET and JavaScript via C++
When transitioning from Aspose.Cells for .NET to Aspose.Cells for JavaScript via C++, there are certain differences to consider in terms of library structure, syntax, and functionality. Below is a comparison to assist you in understanding these differences.
1. Initialization
In .NET, objects are often initialized using constructors. In JavaScript via C++, you will typically create instances using the new
keyword but integrated into 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. Accessing Worksheets
In .NET, you might see code like this to access a worksheet: