<?php
header("Content-type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename = excel_download.xls");
print("<meta http-equiv=\"Content-Type\" content=\"application/vnd.ms-excel; charset=utf-8\">");
$excel = "<table border='1'>
<tr>
<td>이름</td>
<td>부서</td>
<td>나이</td>
<td>성별</td>
</tr>
";
$qry = "SELECT * FROM users";
$res = $mysqli->query($qry);
// DB 에 저장된 데이터 출력
foreach ($res->fetch_object() as $row) {
$excel .= "
<tr>
<td>" . $row->name . "</td>
<td>" . $row->dept . "</td>
<td>" . $row->age . "</td>
<td>" . $row->gender . "</td>
</tr>
";
}
$excel .= "</table>";
echo $excel;
?>