2013年4月6日土曜日

[PHP][PHPExcel]Excelファイルに書き出す

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>PHP Excel</title>
  </head>
  <body>
<?php
require_once '../PHPExcel_1.7.8/Classes/PHPExcel.php';

// Create new PHPExcel object
printWithTime('Create new PHPExcel object<br/>');
$objPHPExcel = new PHPExcel();

// Add some data
printWithTime('Add some data<br/>');
$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', 'Hello')
            ->setCellValue('B2', 'world!');

// Save Excel5 file
$outputFilename = 'php_excel_output.xls';
printWithTime('Write to Excel5 format<br/>');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
$objWriter->save($outputFilename);
printWithTime('File written to Excel5 format<br/>');

print "<br/><br/>";
print "Copy $outputFilename to your local PC and open it!<br/>";

/***********************************************************************
 * 時刻と一緒にデバッグ文表示
 ***********************************************************************/
function printWithTime($str)
{
    print "[" . date('H:i:s') . "] " . $str;
}

?>
  </body>
</html>

0 件のコメント:

コメントを投稿