sheets2list
by hajime_nagahata
HTML
<!DOCTYPE html>
<html>
<head>
<title>Excelファイルのシート名差分チェッカー</title>
</head>
<body>
<h1>Excelファイルのシート名差分チェッカー</h1>
<label for="file1">ファイル1を選択してください:</label>
<input type="file" id="file1" accept=".xlsx">
<br>
<label for="file2">ファイル2を選択してください:</label>
<input type="file" id="file2" accept=".xlsx">
<br>
<button type="button" onclick="compare()">比較する</button>
<br>
<textarea id="result" rows="10" cols="50" readonly></textarea>
<br>
<label for="sheet-names">シート名一覧:</label>
<textarea id="sheet-names" rows="10" cols="50" readonly></textarea>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.3/xlsx.full.min.js"></script>
<script>
function compare() {
// ファイルを取得
const file1 = document.getElementById('file1').files[0];
const file2 = document.getElementById('file2').files[0];
if (!file1 || !file2) {
alert('ファイルを選択してください。');
return;
}
// Excelファイルを読み込む
const reader1 = new FileReader();
reader1.readAsArrayBuffer(file1);
reader1.onload = function (e) {
const data1 = new Uint8Array(reader1.result);
const workbook1 = XLSX.read(data1, { type: 'array' });
const reader2 = new FileReader();
reader2.readAsArrayBuffer(file2);
reader2.onload = function (e) {
const data2 = new Uint8Array(reader2.result);
const workbook2 = XLSX.read(data2, { type: 'array' });
// シート名を取得
const sheetNames1 = workbook1.SheetNames;
const sheetNames2 = workbook2.SheetNames;
// テキストに変換して比較する
const text1 = sheetNames1.join('\n');
const text2 = sheetNames2.join('\n');
if (text1 === text2) {
document.getElementById('result').value = '2つのファイルのシート名は同じです。';
} else {
document.getElementById('result').value = '2つのファイルのシート名に差分があります。\n\nファイル1:\n' + text1 + '\n\nファイル2:\n' + text2;
}
// シート名一覧を表示する
document.getElementById('sheet-names').value = 'ファイル1:\n' + text1 + '\n\nファイル2:\n' + text2;
}
};
}
</script>
</body>
</html>