<?php include "./PHPExcel-1.8/Classes/PHPExcel.php"; $objPHPExcel = new PHPExcel();
$arrChicken = array(); $arrChicken[1] = array("name" => "굽네치킨", "site" => "www.goobne.co.kr", "brand" => "1555064"); $arrChicken[2] = array("name" => "교촌치킨", "site" => "www.kyochon.com", "brand" => "1513807"); $arrChicken[3] = array("name" => "맘스터치", "site" => "www.momstouch.co.kr", "brand" => "1492470"); $arrChicken[4] = array("name" => "BBQ", "site" => "www.bbq.co.kr", "brand" => "1149937"); $arrChicken[5] = array("name" => "BHC", "site" => "www.bhc.co.kr", "brand" => "1028167"); $arrChicken[6] = array("name" => "네네치킨", "site" => "nenechicken.com", "brand" => "717022"); $arrChicken[7] = array("name" => "처갓집양념치킨", "site" => "www.cheogajip.co.kr", "brand" => "344319"); $arrChicken[8] = array("name" => "또래오래", "site" => "www.toreore.com", "brand" => "333237"); $arrChicken[9] = array("name" => "호식이두마리치킨", "site" => "www.9922.co.kr", "brand" => "329789"); $arrChicken[10] = array("name" => "페리카나", "site" => "www.pelicana.co.kr", "brand" => "249857"); $arrChicken[11] = array("name" => "멕시카나", "site" => "www.mexicana.co.kr", "brand" => "235892"); $arrChicken[12] = array("name" => "지코바양념치킨", "site" => "www.gcova.co.kr", "brand" => "214345"); $arrChicken[13] = array("name" => "또봉이통닭", "site" => "ttobongee.com", "brand" => "121882"); $arrChicken[14] = array("name" => "멕시칸치킨", "site" => "www.mexicanchicken.co.kr", "brand" => "88719"); $arrChicken[15] = array("name" => "마파치킨", "site" => "www.mapachicken.co.kr", "brand" => "83152"); $arrChicken[16] = array("name" => "부어치킨", "site" => "www.boor.co.kr", "brand" => "81520"); $arrChicken[17] = array("name" => "훌랄라참숯바베큐", "site" => "www.hoolala.co.kr", "brand" => "22720");
$objPHPExcel -> setActiveSheetIndex(0) -> setCellValue("A1", "NO.") -> setCellValue("B1", "이름") -> setCellValue("C1", "사이트") -> setCellValue("D1", "브랜드평가");
$count = 1; foreach($arrChicken as $key => $val) { $num = 1 + $key; $objPHPExcel -> setActiveSheetIndex(0) -> setCellValue(sprintf("A%s", $num), $key) -> setCellValue(sprintf("B%s", $num), $val['name']) -> setCellValueExplicit(sprintf("C%s", $num), $val['site']) -> setCellValue(sprintf("D%s", $num), $val['brand']); $count++; }
$objPHPExcel -> getActiveSheet() -> getColumnDimension("A") -> setWidth(8); $objPHPExcel -> getActiveSheet() -> getColumnDimension("B") -> setWidth(20); $objPHPExcel -> getActiveSheet() -> getColumnDimension("C") -> setWidth(30); $objPHPExcel -> getActiveSheet() -> getColumnDimension("D") -> setWidth(18);
$objPHPExcel -> getActiveSheet() -> getStyle(sprintf("A1:D%s", $count)) -> getAlignment() -> setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER); $objPHPExcel -> getActiveSheet() -> getStyle(sprintf("A1:D%s", $count)) -> getBorders() -> getAllBorders() -> setBorderStyle(PHPExcel_Style_Border::BORDER_THIN); $objPHPExcel -> getActiveSheet() -> getStyle("A1:D1") -> getFont() -> setBold(true); $objPHPExcel -> getActiveSheet() -> getStyle("A1:D1") -> getFill() -> setFillType(PHPExcel_Style_Fill::FILL_SOLID) -> getStartColor() -> setRGB("CECBCA"); $objPHPExcel -> getActiveSheet() -> getStyle(sprintf("A2:D%s", $count)) -> getFill() -> setFillType(PHPExcel_Style_Fill::FILL_SOLID) -> getStartColor() -> setRGB("F4F4F4");
// getNumberFormat(), setFormatCode() 함수를 사용한다. // setFormatCode() 함수에 천단위를 나타내는 서식인 #,##0 입력한다.
$objPHPExcel -> getActiveSheet() -> getStyle(sprintf("D2:D%s", $count)) -> getNumberFormat() -> setFormatCode("#,##0");
$objPHPExcel -> getActiveSheet() -> setTitle("치킨전문점 브랜드평가 8월"); $objPHPExcel -> setActiveSheetIndex(0); $filename = iconv("UTF-8", "EUC-KR", "치킨전문점");
header("Content-Type:application/vnd.ms-excel"); header("Content-Disposition: attachment;filename=".$filename.".xls"); header("Cache-Control:max-age=0");
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, "Excel5"); $objWriter -> save("php://output"); ?> |