1 개요[ | ]
- PHPExcel create spreadsheet from html table
- PHPExcel HTML 테이블을 엑셀파일로 저장하기
2 사전작업[ | ]
3 table-to-excel.php 작성[ | ]
PHP
Copy
<?php
include 'vendor/PHPExcel/Classes/PHPExcel.php';
// HTML 테이블
$html = '<meta http-equiv="content-type" content="text/html; charset=utf-8">
<table>
<tr><th>ID</th><th>부서ID</th><th>이름</th><th>이메일</th><th>나이</th></tr>
<tr><td>1</td><td>1</td><td>한놈</td><td>maarten@example.com</td><td>24</td></tr>
<tr><td>2</td><td>1</td><td>두시기</td><td>paul@example.com</td><td>30</td></tr>
<tr><td>3</td><td>2</td><td>석삼</td><td>bill.a@example.com</td><td>29</td></tr>
<tr><td>4</td><td>3</td><td>석삼</td><td>bill.g@example.com</td><td>25</td></tr>
</table>';
// 임시파일 저장 후 로드
$tmpfile = '/tmp/'.uniqid().'.html';
file_put_contents($tmpfile, $html);
$reader = new PHPExcel_Reader_HTML;
$content = $reader->load($tmpfile);
unlink( $tmpfile );
// 엑셀 출력
$writer = PHPExcel_IOFactory::createWriter($content, 'Excel2007');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="table-to-excel.xlsx"');
header('Cache-Control: max-age=0');
$writer->save('php://output');
4 같이 보기[ | ]
5 참고[ | ]
- ↑ 해당 속성을 처리해주지 않음. 즉 병합되지 않고 단일 셀로 나옴
편집자 Jmnote Jmnote bot 이상현
로그인하시면 댓글을 쓸 수 있습니다.