<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Excel Splitter</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.16.9/xlsx.full.min.js"></script>
<style>
body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(135deg, #e6f4ff, #b3d9ff);
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
margin: 0;
}
.container {
background: white;
padding: 30px;
border-radius: 15px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
text-align: center;
max-width: 500px;
width: 100%;
}
h1 {
color: #333;
margin-bottom: 20px;
font-size: 24px;
}
#progressBar {
width: 100%;
background-color: #f3f3f3;
border-radius: 10px;
overflow: hidden;
margin: 20px 0;
}
#progressBarFill {
width: 0%;
height: 30px;
background: linear-gradient(90deg, #4caf50, #45a049);
text-align: center;
line-height: 30px;
color: white;
font-weight: bold;
transition: width 0.3s ease;
}
button {
margin: 10px;
padding: 12px 24px;
background: linear-gradient(90deg, #4caf50, #45a049);
color: white;
border: none;
border-radius: 25px;
cursor: pointer;
font-size: 14px;
transition: background 0.3s ease;
}
button:hover {
background: linear-gradient(90deg, #45a049, #4caf50);
}
button:disabled {
background: #ccc;
cursor: not-allowed;
}
#fileName {
margin: 15px 0;
color: #666;
font-size: 14px;
}
.modal-overlay {
display: none;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.5);
z-index: 999;
}
.modal {
display: none;
position: fixed;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
background: white;
padding: 30px;
border-radius: 15px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
text-align: center;
z-index: 1000;
}
.modal button {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h1>Excel Splitter</h1>
<input type="file" id="fileInput" accept=".xlsx, .xls" style="display: none;" />
<label for="fileInput" style="display: inline-block; padding: 12px 24px; background: linear-gradient(90deg, #4caf50, #45a049); color: white; border-radius: 25px; cursor: pointer; font-size: 14px;">
上传文件
</label>
<div id="fileName"></div>
<button id="startButton" disabled>开始分割</button>
<button id="clearButton">清除数据</button>
<div id="progressBar">
<div id="progressBarFill">0%</div>
</div>
<button id="exportButton" disabled>导出文件</button>
</div>
<div class="modal-overlay" id="modalOverlay"></div>
<div class="modal" id="modal">
<p>分割已完成!</p>
<button onclick="closeModal()">关闭</button>
</div>
<script>
let workbook = null;
let chunks = [];
document.getElementById('fileInput').addEventListener('change', function(event) {
const file = event.target.files[0];
if (file) {
document.getElementById('startButton').disabled = false;
document.getElementById('fileName').textContent = `已上传文件: ${file.name}`;
}
});
document.getElementById('startButton').addEventListener('click', function() {
const file = document.getElementById('fileInput').files[0];
if (file) {
const reader = new FileReader();
reader.onload = function(e) {
const data = new Uint8Array(e.target.result);
workbook = XLSX.read(data, {type: 'array'});
const sheetName = workbook.SheetNames[0];
const worksheet = workbook.Sheets[sheetName];
const json = XLSX.utils.sheet_to_json(worksheet);
const chunkSize = 2500;
chunks = [];
for (let i = 0; i < json.length; i += chunkSize) {
chunks.push(json.slice(i, i + chunkSize));
}
document.getElementById('exportButton').disabled = false;
simulateProgress();
};
reader.readAsArrayBuffer(file);
}
});
document.getElementById('clearButton').addEventListener('click', function() {
document.getElementById('fileInput').value = '';
document.getElementById('startButton').disabled = true;
document.getElementById('exportButton').disabled = true;
document.getElementById('fileName').textContent = '';
workbook = null;
chunks = [];
updateProgress(0);
});
document.getElementById('exportButton').addEventListener('click', function() {
if (workbook && chunks.length > 0) {
const newWorkbook = XLSX.utils.book_new();
chunks.forEach((chunk, index) => {
const newSheet = XLSX.utils.json_to_sheet(chunk);
XLSX.utils.book_append_sheet(newWorkbook, newSheet, `Sheet${index + 1}`);
});
XLSX.writeFile(newWorkbook, 'split_excel.xlsx');
}
});
function updateProgress(percent) {
const progressBarFill = document.getElementById('progressBarFill');
progressBarFill.style.width = percent + '%';
progressBarFill.textContent = percent + '%';
}
function simulateProgress() {
let percent = 0;
const interval = setInterval(() => {
percent += 10;
updateProgress(percent);
if (percent >= 100) {
clearInterval(interval);
showModal();
}
}, 300);
}
function showModal() {
document.getElementById('modal').style.display = 'block';
document.getElementById('modalOverlay').style.display = 'block';
}
function closeModal() {
document.getElementById('modal').style.display = 'none';
document.getElementById('modalOverlay').style.display = 'none';
}
</script>
</body>
</html>
HTML
格式化
支持Emmet,输入 p 后按 Tab键试试吧!
<head> ... </head>
<body>
</body>