[PHP] 엑셀 출력을 위한 헤더(Header) 선언
반응형
[PHP] 엑셀 출력을 위한 헤더(Header) 선언
엑셀 출력을 위해서는 테이블 구조의 HTML 페이지를 구성 후 상단에 헤더 선언을 추가하면 엑셀 파일로 출력이 가능함
header 선언
$filename = "파일이름.xls";
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=".$filename);
header("Content-Description: PHP4 Generated Data");
예제
<?php
$filename = "회원목록.xls";
header("Content-type: application/vnd.ms-excel");
header("Content-Disposition: attachment; filename=".$filename);
header("Content-Description: PHP4 Generated Data");
?>
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<table border="1">
<tr>
<th>이름</th>
<th>성별</th>
<th>나이</th>
<th>전화번호</th>
</tr>
<tr>
<td>홍길동</td>
<td>남</td>
<td>30</td>
<td>010-1234-5678</td>
</tr>
</table>
</body>
</html>
반응형
'Programming > PHP' 카테고리의 다른 글
[PHP] 데이터가 문자열인지 배열인지 확인하기 (0) | 2022.10.25 |
---|---|
[PHP] fopen 파일 저장 (0) | 2022.10.24 |
[PHP] CURL 데이터 보내고 받기 (0) | 2022.10.21 |
[PHP] 특정 태그 제거 함수 (0) | 2022.10.21 |
[PHP] 폴더 생성 함수 (0) | 2022.10.21 |