랜덤 팀짜기·조짜기·그룹 생성기 (코드 무료 공개)

랜덤 팀 나누기

랜덤 팀 나누기

이름을 줄마다 입력하고, 만들 팀 수를 입력하세요.


팀 수:

👇 확인하기 전 이 추천도 놓치지 마세요 👇

아래는 코드 내용입니다.

<!DOCTYPE html>
<html lang="ko">
<head>
    <meta charset="UTF-8">
    <title>랜덤 팀 나누기</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.full.min.js"></script>
    <style>
        body { font-family: 'Arial', sans-serif; padding: 2rem; }
        h1 { font-size: 2rem; }
        textarea { width: 100%; height: 150px; margin-top: 1rem; }
        input[type='number'] { width: 50px; }
        .btn { margin-top: 1rem; padding: 0.5rem 1rem; font-size: 1rem; }
        #result { margin-top: 2rem; white-space: pre-wrap; background: #f9f9f9; padding: 1rem; border-radius: 8px; border: 1px solid #ccc; }
        .ad-area { margin-top: 1.5rem; text-align: center; }
    </style>
</head>
<body>
    <h1>랜덤 팀 나누기</h1>
    <p>이름을 줄마다 입력하고, 만들 팀 수를 입력하세요.</p>

<textarea id="nameList" placeholder="김철수
박영희
이민호"></textarea>
    <br>
    팀 수: <input type="number" id="teamCount" min="1" value="2">
    <br>
    <button class="btn" onclick="generateTeams()">팀 나누기</button>
    <button class="btn" onclick="downloadExcel()">엑셀 다운로드</button>

    <script>
        let finalTeams = [];

        function generateTeams() {
            const names = document.getElementById("nameList").value.trim().split(/\n|\r/).filter(n => n);
            const teamCount = parseInt(document.getElementById("teamCount").value);
            if (teamCount < 1 || names.length < teamCount) {
                alert("팀 수가 이름 수보다 많을 수 없습니다.");
                return;
            }

            // 광고 영역 중심으로 스크롤
            document.querySelector('.ad-area').scrollIntoView({ behavior: 'smooth' });
            document.getElementById('result').innerText = '잠시만요... 결과 확인 중...';

            setTimeout(() => {
                const shuffled = names.sort(() => 0.5 - Math.random());
                finalTeams = Array.from({ length: teamCount }, () => []);
                shuffled.forEach((name, i) => {
                    finalTeams[i % teamCount].push(name);
                });

                let output = '';
                finalTeams.forEach((team, idx) => {
                    output += `\n[팀 ${idx + 1}]\n` + team.join("\n") + "\n";
                });

                document.getElementById("result").innerText = output;
            }, 1200);
        }

        function downloadExcel() {
            if (finalTeams.length === 0) {
                alert("먼저 팀을 나눠주세요.");
                return;
            }

            const wb = XLSX.utils.book_new();
            finalTeams.forEach((team, idx) => {
                const ws = XLSX.utils.aoa_to_sheet(team.map(n => [n]));
                XLSX.utils.book_append_sheet(wb, ws, `팀 ${idx + 1}`);
            });
            XLSX.writeFile(wb, "랜덤팀.xlsx");
        }
    </script>
</body>
</html>

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다