- 정보공유
[그누보드팁] 엑셀 다운로드 할때 깨질경우.
가장 기본적인 예제 입니다.
가끔 Spreadsheet::WriteExcel 플러그인을 사용했는데 깨질경우 기본적인 방법으로 해야할때가 있습니다.
<?php
header( "Content-type: application/vnd.ms-excel" );
header( "Content-type: application/vnd.ms-excel; charset=utf-8");
header( "Content-Disposition: attachment; filename=bookinglist-".date("ymd", time()).".xls" );
header( "Content-Description: PHP4 Generated Data" );
?>
<html xmlns:x="urn:schemas-microsoft-com:office:excel">
<meta http-equiv='Content-Type' content='text/html; charset=euc-kr'>
<!--[if gte mso 9]><xml>
<x:ExcelWorkbook>
<x:ExcelWorksheets>
<x:ExcelWorksheet>
<x:Name>원서목록</x:Name>
<x:WorksheetOptions>
<x:Print>
<x:ValidPrinterInfo/>
</x:Print>
</x:WorksheetOptions>
</x:ExcelWorksheet>
</x:ExcelWorksheets>
</x:ExcelWorkbook>
</xml>
<![endif]-->
<?php
$data = array('항목1','항목2','항목3','항목4','항목5');
$col = 0;
echo '<table border="1">';
echo '<tr>';
foreach($data as $cell) {
echo '<td>'.$cell.'</td>';
}
echo '</tr>';
echo '<tr>';
echo '<td> 내용1</td>';
echo '<td> 내용2</td>';
echo '<td> 내용3</td>';
echo '<td> 내용4</td>';
echo '<td> 내용5</td>';
echo '</tr>';
echo '</table>';
?>
추가로 td값에 사용할수 있는 옵션은
문자서식 : style="mso-number-format:\@"
날짜서식 : style="mso-number-format:Short Date"
기타 다른 서식이 많습니다.