您的位置:首页 > 编程语言 > PHP开发

PHP生成word文档,表格实例

2015-03-27 13:42 232 查看
<?php
require_once 'PHPWord.php';

// New Word Document
$PHPWord = new PHPWord();

// New portrait section
$section = $PHPWord->createSection();
$PHPWord->addFontStyle('rStyle', array('bold'=>true,'color'=>'000000','size'=>16));
$PHPWord->addParagraphStyle('pStyle', array('align'=>'center'));
$section->addText('×××公司招聘信息', 'rStyle', 'pStyle');
$section->addTextBreak(2);

// Define table style arrays
$styleTable = array('borderSize'=>6, 'borderColor'=>'006699', 'cellMargin'=>80);

// Add table style
$PHPWord->addTableStyle('myOwnTableStyle', $styleTable);

// Add table
$table = $section->addTable('myOwnTableStyle');
$fontStyle = array('bold'=>true, 'align'=>'center');

// Add more rows / cells
$table->addRow();
$table->addCell(2000)->addText("单位名称",$fontStyle);
$table->addCell(3000)->addText("",$fontStyle);
$table->addCell(2000)->addText("详细地址",$fontStyle);
$table->addCell(3000)->addText("",$fontStyle);

$table->addRow();
$table->addCell(2000)->addText("场所负责人",$fontStyle);
$table->addCell(3000)->addText("",$fontStyle);
$table->addCell(2000)->addText("联系电话",$fontStyle);
$table->addCell(3000)->addText("",$fontStyle);

$styleTable2 = array('borderColor'=>'006699', 'borderLeftSize'=>6,'borderRightSize'=>6,'cellMargin'=>80);
$fontStyle2 = array('align'=>'center');
// Add table style
$PHPWord->addTableStyle('myOwnTableStyle2', $styleTable2);
for($i=1;$i<=5;$i++){
$table2 = $section->addTable('myOwnTableStyle2');
$table2->addRow();
$table2->addCell(10000)->addText("服务岗位".$i,$fontStyle);
$table3 = $section->addTable('myOwnTableStyle');
$table3->addRow();
$table3->addCell(2000)->addText("岗位内容",$fontStyle2);
$table3->addCell(3000)->addText("",$fontStyle2);
$table3->addCell(2000)->addText("需求数量",$fontStyle2);
$table3->addCell(3000)->addText("",$fontStyle2);
$table3->addRow();
$table3->addCell(2000)->addText("服务时数",$fontStyle2);
$table3->addCell(3000)->addText("",$fontStyle2);
$table3->addCell(2000)->addText("服务周期",$fontStyle2);
$table3->addCell(3000)->addText("",$fontStyle2);
}
$styleTable3 = array('borderColor'=>'006699', 'borderLeftSize'=>6, 'borderBottomSize'=>6,'borderRightSize'=>6,'cellMargin'=>80);
$fontStyle3 = array('align'=>'center');
$cellStyle3 = array('borderColor'=>'006699', 'borderRightSize'=>6);
// Add table style
$PHPWord->addTableStyle('myOwnTableStyle3', $styleTable3);
$table4 = $section->addTable('myOwnTableStyle3');
$table4->addRow(2000);
$table4->addCell(3333,$cellStyle3)->addText("本单位意见",$fontStyle3);
$table4->addCell(3333,$cellStyle3)->addText("主管部门意见",$fontStyle3);
$table4->addCell(3334)->addText("集团总部意见",$fontStyle3 );
//Two enter
$section->addTextBreak(2);
//Add image
$section->addImage('logo.jpg', array('width'=>100, 'height'=>100,'align'=>'right'));

$objWrite = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');
$objWrite->save('index.docx');
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: