JavaScript経由のC++で1904日付システムを実装
Contents
[
Hide
]
Microsoft Excel は、2つの日付システムをサポートしています。1900日付システム(Windows用Excelに標準搭載)と1904日付システムです。1904日付システムは、Macintosh Excelファイルとの互換性を提供するために通常使用され、Mac版Excelを使用している場合はデフォルトのシステムです。これらは、Aspose.Cells for JavaScriptをC++経由で使用してExcelファイルの1904日付システムを設定できます。
Microsoft Excelで1904日付システムを実装する方法(例:Microsoft Excel 2003):
- ツールメニューからオプションを選択し、計算タブを選択します。
- 1904年日付システムオプションを選択します。
- OK をクリックします。
| Microsoft Excelで1904年日付システムを選択 |
|---|
![]() |
Aspose.CellsのAPIを使用してこの機能を実現するサンプルコードを以下に示します。
<!DOCTYPE html>
<html>
<head>
<title>Aspose.Cells Example</title>
</head>
<body>
<h1>Aspose.Cells Example - Enable 1904 Date System</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 } = 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();
// Instantiating a Workbook object by opening the uploaded Excel file
const workbook = new Workbook(new Uint8Array(arrayBuffer));
// Implement 1904 date system
workbook.settings.date1904 = true;
// Saving the modified Excel file
const outputData = workbook.save(SaveFormat.Xlsx);
const blob = new Blob([outputData]);
const downloadLink = document.getElementById('downloadLink');
downloadLink.href = URL.createObjectURL(blob);
downloadLink.download = 'Mybook.out.xlsx';
downloadLink.style.display = 'block';
downloadLink.textContent = 'Download Modified Excel File';
document.getElementById('result').innerHTML = '<p style="color: green;">1904 date system enabled. Click the download link to get the modified file.</p>';
});
</script>
</html>
