1. 程序简介
本程序是一个网页版抽奖工具,支持三个奖项的抽奖:
- 特等奖:3人
- 一等奖:10人
- 二等奖:20人
2. 准备工作
准备Excel文件:
- 创建Excel文件,命名为"抽奖.xlsx"(或其他名称)
- 在第一列添加表头"姓名"
- 在姓名列下方填入所有参与抽奖的人员姓名
注意:Excel文件格式要求:
- 必须包含"姓名"列
- 支持的文件格式:.xlsx, .xls, .csv
- 确保姓名不重复
3. 操作步骤
- 上传名单:点击"选择文件"按钮选择准备好的Excel文件文件上传成功后,抽奖按钮将被激活
- 开始抽奖:点击对应奖项的抽奖按钮程序会自动进行名字滚动动画约5秒后显示中奖结果中奖者将以5人一行的方式整齐显示
- 保存结果:抽奖完成后,点击"保存中奖结果"按钮程序会自动生成"中奖结果.xlsx"文件文件会自动下载到您的下载文件夹
4. 注意事项
- 请确保浏览器允许下载文件,否则可能无法保存结果
- 抽奖过程中请勿刷新页面,否则将丢失已抽取的结果
- 建议使用Chrome、Firefox、Edge等现代浏览器
- 确保参与人数大于需要抽取的总人数
- 已中奖的人员不会参与后续抽奖
5. 常见问题
Q: 为什么上传文件后按钮仍然是灰色的?
A: 请检查Excel文件格式是否正确,确保包含"姓名"列。
Q: 抽奖结果如何查看?
A: 结果会直接显示在页面中央,每行显示5个中奖者。
Q: 中奖结果丢失怎么办?
A: 请及时点击"保存中奖结果"按钮保存结果,避免刷新页面。
Q: 可以重复抽取同一奖项吗?
A: 每个奖项只能抽取一次,如需重新抽奖,请刷新页面重新开始。
技术支持:
如遇到使用问题,请检查:
- 是否使用了最新版本的浏览器
- Excel文件格式是否正确
- 网络连接是否正常
趣味抽奖程序
趣味抽奖程序
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.16.9/xlsx.full.min.js"></script>
<script>
let participants = [];
let winners = {
"特等奖": [],
"一等奖": [],
"二等奖": []
};
document.getElementById('fileInput').addEventListener('change', handleFileSelect);
function handleFileSelect(event) {
const file = event.target.files[0];
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]];
participants = XLSX.utils.sheet_to_json(firstSheet);
enableButtons();
};
reader.readAsArrayBuffer(file);
}
function enableButtons() {
document.querySelectorAll('.lottery-button').forEach(button => {
button.disabled = false;
});
}
function disableButtons() {
document.querySelectorAll('.lottery-button').forEach(button => {
button.disabled = true;
});
}
function displayWinners(prize, winners) {
const resultElement = document.getElementById('result');
resultElement.innerHTML = ''; // 清空现有内容
// 创建奖项容器
const container = document.createElement('div');
// 添加奖项标题
const titleDiv = document.createElement('div');
titleDiv.className = 'prize-title';
titleDiv.textContent = `${prize}中奖者:`;
container.appendChild(titleDiv);
// 创建网格容器
const gridDiv = document.createElement('div');
gridDiv.className = 'winners-grid';
// 添加获奖者
winners.forEach(name => {
const winnerDiv = document.createElement('div');
winnerDiv.className = 'winner-item';
winnerDiv.textContent = name;
gridDiv.appendChild(winnerDiv);
});
container.appendChild(gridDiv);
resultElement.appendChild(container);
}
async function startLottery(prize, numWinners) {
if (participants.length < numWinners) {
alert(`剩余人数不足,无法抽取 ${prize}!`);
return;
}
disableButtons();
const resultElement = document.getElementById('result');
// 滚动效果
for (let i = 0; i < 50 i const randomname='participants[Math.floor(Math.random()' participants.length. resultelement.textcontent='randomName;' await new> setTimeout(resolve, 100));
}
// 抽取获奖者
const currentWinners = [];
for (let i = 0; i < numwinners i const winnerindex='Math.floor(Math.random()' participants.length currentwinners.pushparticipantswinnerindex. participants.splicewinnerindex 1 winnersprize='currentWinners;' displaywinnersprize currentwinners enablebuttons function saveresults if> arr.length > 0)) {
alert('没有中奖者!');
return;
}
const rows = [];
Object.entries(winners).forEach(([prize, names]) => {
names.forEach(name => {
rows.push([prize, name]);
});
});
const ws = XLSX.utils.aoa_to_sheet([['奖项', '姓名'], ...rows]);
const wb = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(wb, ws, '中奖结果');
XLSX.writeFile(wb, '中奖结果.xlsx');
}
</script>