# 기본

$fname = date("YmdHis")."_excel";
header( "Content-type: application/vnd.ms-excel" );
header( "Content-Disposition: attachment; filename=$fname.xls" );
header( "Content-Description: PHP4 Generated Data" );

echo "<style type='text/css'> .cstring { mso-number-format:'\@'; text-align: left; } </style> ";
echo "<meta http-equiv='Content-Type' content='application/vnd.ms-excel; charset=euc-kr'>";

 

 


# 엑셀 2003버젼

<?
$fname = date("YmdHis")."_excel";
header( "Content-type: application/vnd.ms-excel" );
header( "Content-Disposition: attachment; filename=$fname.xls" );
header( "Content-Description: PHP4 Generated Data" );
?>
<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
<meta http-equiv='Content-Type' content='application/vnd.ms-excel; charset=euc-kr'>
<style type='text/css'> .cstring { mso-number-format:'\@'; text-align: left; } </style>
<!--[if gte mso 9]><xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>Sheet1</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>270</x:DefaultRowHeight>
     <x:Selected/>
     <x:Panes>
      <x:Pane>
       <x:Number>3</x:Number>
       <x:ActiveRow>2</x:ActiveRow>
       <x:ActiveCol>3</x:ActiveCol>
      </x:Pane>
     </x:Panes>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet2</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>270</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet3</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>270</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
  <x:WindowHeight>8955</x:WindowHeight>
  <x:WindowWidth>14280</x:WindowWidth>
  <x:WindowTopX>600</x:WindowTopX>
  <x:WindowTopY>135</x:WindowTopY>
  <x:ProtectStructure>False</x:ProtectStructure>
  <x:ProtectWindows>False</x:ProtectWindows>
 </x:ExcelWorkbook>
</xml><![endif]-->

<?
echo "<table>";
echo "<tr>";
echo "<td><b>신청인</b></td>";
echo "<td><b>전화번호</b></td>";
echo "<td><b>선택통신사</b></td>";
echo "<td><b>선택기종</b></td>";
echo "<td><b>선택요금제</b></td>";
echo "<td><b>할부개월수</b></td>";
echo "<td><b>결합상품유무</b></td>";
echo "<td><b>결과</b></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 "<td>6</td>";
echo "<td>7</td>";
echo "<td>8</td>";
echo "</tr>";
echo "</table>";
?>

 

@ 셀에 줄그어지게

<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40">
<meta http-equiv='Content-Type' content='application/vnd.ms-excel; charset=euc-kr'>
<style type='text/css'> .cstring { mso-number-format:'\@'; text-align: left; } </style>
<!--[if gte mso 9]><xml>
 <x:ExcelWorkbook>
  <x:ExcelWorksheets>
   <x:ExcelWorksheet>
    <x:Name>Sheet1</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>270</x:DefaultRowHeight>
     <x:Selected/>
     <x:Panes>
      <x:Pane>
       <x:Number>3</x:Number>
       <x:ActiveRow>2</x:ActiveRow>
       <x:ActiveCol>3</x:ActiveCol>
      </x:Pane>
     </x:Panes>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet2</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>270</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
   <x:ExcelWorksheet>
    <x:Name>Sheet3</x:Name>
    <x:WorksheetOptions>
     <x:DefaultRowHeight>270</x:DefaultRowHeight>
     <x:ProtectContents>False</x:ProtectContents>
     <x:ProtectObjects>False</x:ProtectObjects>
     <x:ProtectScenarios>False</x:ProtectScenarios>
    </x:WorksheetOptions>
   </x:ExcelWorksheet>
  </x:ExcelWorksheets>
  <x:WindowHeight>8955</x:WindowHeight>
  <x:WindowWidth>14280</x:WindowWidth>
  <x:WindowTopX>600</x:WindowTopX>
  <x:WindowTopY>135</x:WindowTopY>
  <x:ProtectStructure>False</x:ProtectStructure>
  <x:ProtectWindows>False</x:ProtectWindows>
 </x:ExcelWorkbook>
</xml><![endif]-->

 

 

 

 

 

# 엑셀 2007버젼 [ phpexcel 다운로드: http://phpexcel.codeplex.com/ ]

<?
require_once './PHPExcel.php';

$objPHPExcel = new PHPExcel();
$sheet      = $objPHPExcel->getActiveSheet();

$sheetIndex = $objPHPExcel->setActiveSheetIndex(0);


//파일명
$filename = "뭔파일123abc";

 

//타이틀
$sheetIndex ->setCellValue('A1', iconv("EUC-KR", "UTF-8","신청인"))
->setCellValue('B1', iconv("EUC-KR", "UTF-8","전화번호"))
->setCellValue('C1', iconv("EUC-KR", "UTF-8","선택통신사"))
->setCellValue('D1', iconv("EUC-KR", "UTF-8","선택기종"))
->setCellValue('E1', iconv("EUC-KR", "UTF-8","선택요금제"))
->setCellValue('F1', iconv("EUC-KR", "UTF-8","할부개월수"))
->setCellValue('G1', iconv("EUC-KR", "UTF-8","결합상품유무"))
->setCellValue('H1', iconv("EUC-KR", "UTF-8","결과"))
->setCellValue('I1', iconv("EUC-KR", "UTF-8","신청일시"));

$sheetIndex->getStyle('A1')->getFont()->setBold(true);
$sheetIndex->getStyle('B1')->getFont()->setBold(true);
$sheetIndex->getStyle('C1')->getFont()->setBold(true);
$sheetIndex->getStyle('D1')->getFont()->setBold(true);
$sheetIndex->getStyle('E1')->getFont()->setBold(true);
$sheetIndex->getStyle('F1')->getFont()->setBold(true);
$sheetIndex->getStyle('G1')->getFont()->setBold(true);
$sheetIndex->getStyle('H1')->getFont()->setBold(true);
$sheetIndex->getStyle('I1')->getFont()->setBold(true);


$sheetIndex ->setCellValue("A$number", iconv("EUC-KR", "UTF-8",$name))
->setCellValue("B$number", iconv("EUC-KR", "UTF-8",전화번호))
->setCellValue("C$number", iconv("EUC-KR", "UTF-8",통신사))
->setCellValue("D$number", iconv("EUC-KR", "UTF-8",기종))
->setCellValue("E$number", iconv("EUC-KR", "UTF-8",요금제))
->setCellValue("F$number", iconv("EUC-KR", "UTF-8",개월수))
->setCellValue("G$number", iconv("EUC-KR", "UTF-8",결합상품))
->setCellValue("H$number", iconv("EUC-KR", "UTF-8",결과))
->setCellValue("I$number", iconv("EUC-KR", "UTF-8",일자));

 

// Rename sheet
$objPHPExcel->getActiveSheet()->setTitle("Sheet1");

// Set active sheet index to the first sheet, so Excel opens this as the first sheet
$objPHPExcel->setActiveSheetIndex(0);


header('Content-Type: application/vnd.ms-excel');
header("Content-Disposition: attachment;filename=$filename.xls");
header('Cache-Control: max-age=0');
header("Content-Transfer-Encoding:binary");
header("Content-charset:euc-kr");


$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save('php://output');
exit;
?>

 


# 기본소스 - 셀합치기

<?

 require_once './PHPExcel.php';
   
 $objPHPExcel = new PHPExcel();

    $sheet      = $objPHPExcel->getActiveSheet();

    // 글꼴
    //$sheet->getDefaultStyle()->getFont()->setName('맑은 고딕');

    $sheetIndex = $objPHPExcel->setActiveSheetIndex(0);


    // 제목 - 셀합치기
    $sheetIndex->setCellValue('A1',iconv("EUC-KR", "UTF-8", "제목"));
    $sheetIndex->mergeCells('A1:G1');
    $sheetIndex->getStyle('A1')->getFont()->setSize(20)->setBold(true);
    $sheetIndex->getStyle('A1')->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);


 // 내용
    $sheetIndex ->setCellValue('A2', 'one')
                ->setCellValue('B2', '12312312')
                ->setCellValue('C2', 'three')
                ->setCellValue('D2', '2560000')
    ->setCellValue('E2', iconv("EUC-KR", "UTF-8","너가"))
    ->setCellValue('F2', "뭐가")
    ->setCellValue("G2", iconv("EUC-KR", "UTF-8","1너가aaa그러가123"));

 

$filename = "뭔파일123abc";

header('Content-Type: application/vnd.ms-excel');
header("Content-Disposition: attachment;filename=$filename.xls");
header('Cache-Control: max-age=0');
header("Content-Transfer-Encoding:binary");
header("Content-charset:euc-kr");


    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
    $objWriter->save('php://output');
 
?>

 

 

 

'php, mysql' 카테고리의 다른 글

페이지 로딩시간 구하기  (0) 2017.04.13
자주쓰는 함수 php라이브러리  (0) 2017.04.13
마감시간 구하기 - 남은시간 구하기  (0) 2017.04.13
문자 랜덤출력  (0) 2017.04.13
download 속도제한  (0) 2017.04.13




+ Recent posts