Search...
그누보드 쉽게 엑셀 파일 만들기
설명 :
쉽게 엑셀 파일을 만든 방법이 있다.
보통 이런 방식으로 만들긴하는데 만약에 테이블 구조가 복잡하면 이런 방법 보다 라이브러리 써서 만든게 좋다.
우선 쉽게 만든 방법에 대해서 글 올린다.
php
<?php
$sub_menu = "500300";
include_once "./_common.php";
auth_check($auth[$sub_menu], "w");
// 상품이 많을 경우 대비 설정변경
set_time_limit ( 0 );
ini_set('memory_limit', '50M');
$fileName = date('Y-m-d H:i:s')."_상담신청목록";
$sql = "select * from {$g5['reser_content_table']} ORDER BY re_no DESC";
$result = sql_query($sql);
$list = array();
for($i=0;$row = sql_fetch_array($result);$i++) {
$list[$i] = $row;
}
header('Content-Type: application/vnd.ms-excel');
header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
header("Content-Disposition: attachment; filename='{$fileName}'.xls");
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('content-transfer-encoding: binary');
?>
<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title><?=$fileName?></title>
</head>
<body>
<table border="1">
<thead>
<tr>
<th scope="col">번호</th>
<th scope="col">진료과목</th>
<th scope="col">진료구분</th>
<th scope="col">휴대번호</th>
<th scope="col">진료시간</th>
<th scope="col">제목</th>
<th scope="col">성함</th>
<th scope="col">상태</th>
<th scope="col">내용</th>
</tr>
</thead>
<tbody>
<?php foreach ($list as $value) : ?>
<tr>
<td><?=$value['re_no']?></td>
<td><?=$value['category']?></td>
<td><?=$value['division']?></td>
<td><?=$value['phone']?></td>
<td><?=$value['reservetime']?></td>
<td><?=$value['title']?></td>
<td><?=$value['mb_name']?></td>
<td><?=$value['status']?></td>
<td><?=$value['content']?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</body>
</html>
이렇게 바이너리를 엑셀로 변환해서 하면 페이지 접근했을때 엑셀 다운 받기가 된다.
간단하게 목록만 따로 출력되는거라서 쉽게 구현 된다.
여기까지 설명하겠다.