ERP/test-xlsx.html

38 lines
1.3 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>测试XLSX库</title>
</head>
<body>
<h1>XLSX库测试</h1>
<input type="file" id="file-input" accept=".xlsx,.xls">
<div id="result"></div>
<script src="https://cdn.jsdelivr.net/npm/xlsx@0.18.5/dist/xlsx.full.min.js"></script>
<script>
document.getElementById('file-input').addEventListener('change', function(e) {
const file = e.target.files[0];
if (!file) return;
console.log('XLSX typeof:', typeof XLSX);
console.log('XLSX version:', XLSX.version);
const reader = new FileReader();
reader.onload = function(e) {
const data = new Uint8Array(e.target.result);
const workbook = XLSX.read(data, { type: 'array' });
const firstSheet = workbook.Sheets[workbook.SheetNames[0]];
const jsonData = XLSX.utils.sheet_to_json(firstSheet, { header: 1 });
document.getElementById('result').innerHTML = `
<h2>解析结果:</h2>
<pre>${JSON.stringify(jsonData, null, 2)}</pre>
`;
};
reader.readAsArrayBuffer(file);
});
</script>
</body>
</html>