PHPExcel 로 엑셀파일 만들기
require_once("./plugin/PHPExcel-1.8/Classes/PHPExcel.php");
$objPHPExcel = new PHPExcel();
$objPHPExcel->getProperties()->setCreator('Maarten Balliauw')
->setLastModifiedBy('Maarten Balliauw')
->setTitle('Office 2007 XLSX Test Document')
->setSubject('Office 2007 XLSX Test Document')
->setDescription('Test document for Office 2007 XLSX, generated using PHP classes.');
// Create the worksheet
$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1', '번호')
->setCellValue('B1', '제목')
->setCellValue('C1', '이미지')
->setCellValue('D1', '내용')
->setCellValue('E1', '비고')
->setCellValue('F1', '날짜');
$objPHPExcel->getActiveSheet()->getStyle("A1")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle("B1")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle("C1")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle("D1")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle("E1")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle("F1")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$tmpArray = array();
foreach($list as $key => $row)
{
$cell_key = $key + 2;
//이미지 추가
$path = $_SERVER['DOCUMENT_ROOT'].$row['photo'];
$objDrawing = new PHPExcel_Worksheet_Drawing();
//$objDrawing->setResizeProportional(true);
$objDrawing->setPath($path);
$objDrawing->setHeight(120);
$objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
$objDrawing->setCoordinates('C'.$cell_key);
$objPHPExcel->getActiveSheet()->setCellValue('A'.$cell_key, $row['idx'])
->setCellValue('B'.$cell_key, $row['title'])
//->setCellValue('C'.$cell_key, $row['photo'])
->setCellValue('D'.$cell_key, $row['content'])
->setCellValue('E'.$cell_key, $row['memo'])
->setCellValue('F'.$cell_key, $row['reg_time']);
//세로정렬
$objPHPExcel->getActiveSheet()->getStyle('A'.$cell_key.':F'.$cell_key)->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
//가로정렬
$objPHPExcel->getActiveSheet()->getStyle('A'.$cell_key)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('C'.$cell_key)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
$objPHPExcel->getActiveSheet()->getStyle('F'.$cell_key)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
//세로높이
$objPHPExcel->getActiveSheet()->getRowDimension($cell_key)->setRowHeight(100);
}
//각각의 셀 크기를 지정함
$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(5);
$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(30);
$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(40);
$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(40);
$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(20);
//위에서 쓴 엑셀을 저장하고 다운로드 합니다.
header('Content-Type: application/vnd.ms-excel;charset=utf-8');
header('Content-type: application/x-msexcel;charset=utf-8');
header('Content-Disposition: attachment;filename="notice.xls"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');