booking_down.php
<?php
include_once('./_common.php');
function column_char($i) { return chr( 65 + $i ); }
include_once(G5_LIB_PATH.'/PHPExcel.php');
// $bo_table = $_GET["bo_table"];
$bo_table = "g5_write_booking";
// $wr_id = $_GET["wr_id"];
$headers = array('이름', 'ID', '작성일시','댓글');
$widths = array(20, 20, 20, 40);
$header_bgcolor = 'FFABCDEF';
$last_char = column_char(count($headers) - 1);
$sql = " select * from g5_write_{$bo_table}";
$result = sql_query($sql);
for($i=1; $row=sql_fetch_array($result); $i++) {
$rows[] =
array($row['wr_name'],
$row['mb_id'],
$row['wr_datetime'],
$row['wr_content']);
}
$data = array_merge(array($headers), $rows);
$excel = new PHPExcel();
$excel->setActiveSheetIndex(0)->getStyle( "A1:${last_char}1" )->getFill()->setFillType(PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB($header_bgcolor);
$excel->setActiveSheetIndex(0)->getStyle( "A:$last_char" )->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER)->setWrapText(true);
foreach($widths as $i => $w) $excel->setActiveSheetIndex(0)->getColumnDimension( column_char($i) )->setWidth($w);
$excel->getActiveSheet()->fromArray($data,NULL,'A1');
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"commentlist-".date("ymd", time()).".xls\"");
header("Cache-Control: max-age=0");
$writer = PHPExcel_IOFactory::createWriter($excel, 'Excel5');
$writer->save('php://output');
?>