JavaScript経由のC++による比較と移行
Contents
[
Hide
]
** .NETとJavaScriptの比較 C++**
.NETからAspose.Cells for JavaScriptへの移行時には、ライブラリ構造、構文、機能面で考慮すべき違いがあります。以下にその比較を示します。
1. 初期化
.NETでは、オブジェクトはしばしばコンストラクタを使用して初期化されます。JavaScript経由のC++では、通常newキーワードを使ってインスタンスを作成しますが、それは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. ワークシートへのアクセス
.NETでは次のようなコードでワークシートにアクセスできます: