<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();
$sheet = $objPHPExcel->setActiveSheetIndex(0);
// フォント
printWithTime('Set default font<br/>');
$sheet->getDefaultStyle()->getFont()->setName('メイリオ');
// cell に「折り返して全体を表示 (Wrap text)」 属性を付ける
$sheet->getDefaultStyle()->getAlignment()->setWrapText(true);
// cell に「文字の配置 - 縦位置 = 上詰め (vertical = top)」属性を付ける
$sheet->getDefaultStyle()->getAlignment()->setVertical('top');
// Add data
printWithTime('Add data<br/>');
$str = "Hello, world.\nThis is a pen.\nGood bye.";
$sheet->setCellValue('A1', 1);
$sheet->setCellValue('B1', $str);
// Save Excel5 file
$outputFilename = 'php_excel3_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>
2013年4月6日土曜日
[PHP][PHPExcel]Cellに属性を付ける
Cellに「折り返して全体を表示」「文字の配置 - 縦位置 = 上詰め」属性を付ける
登録:
コメントの投稿 (Atom)
0 件のコメント:
コメントを投稿