下载:
http://phpword.codeplex.com/releases/view/49543
解压缩,添加以下文件至项目中:
PHPWord // 文件夹
PHPWord.class.php // 文件
然后在项目中引用PHPWord.class.php
;
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
设置样式
$PHPWord->addFontStyle('content', array('bold'=>false, 'size'=>11));
$PHPWord->addFontStyle('rstyle', array('bold'=>true, 'italic'=>false, 'size'=>18,'align'=>'center'));
$PHPWord->addFontStyle('tstyle', array('bold'=>true, 'italic'=>false, 'size'=>11));
$PHPWord->addParagraphStyle('pstyle', array('align'=>'center', 'spaceAfter'=>100));
$PHPWord->addFontStyle('end_style', array('italic'=>false, 'size'=>11,'align'=>'right'));
$PHPWord->addParagraphStyle('endstyle', array('align'=>'right', 'spaceAfter'=>100));
设置文字内容
$title = iconv('utf-8','GB2312//IGNORE','借款协议');
$section->addText($title,'rstyle','pstyle');
$section->addTextBreak(2); # 分段 2 设置段落距离
$section->addText(iconv('utf-8','GB2312//IGNORE',$str),'tstyle'); #一段内容
设置表格
# 设置表格样式
$cellStyle = array('valign'=>'center','align'=>'center');
$styleTable = array('borderSize'=>6, 'borderColor'=>'000000','cellMargin'=>80,'alignMent'=>'center');
$PHPWord->addTableStyle('myTable', $styleTable);
# 创建一个表格
$table = $section->addTable('myTable');
$table->addRow(300); // 行
$table->addCell(2300,$cellStyle)->addText(iconv('utf-8','GB2312//IGNORE',