php 报表模板_PHPWord插件创建表格及模板替换技术记录说明(含PHPWord文件及中文技术文档下载)...

1.模板替换功能require_once 'PHPWord.php';

require_once 'PHPWord/IOFactory.php';

$PHPWord = new PHPWord();

$template = $PHPWord->loadTemplate('PHPWord/mb/test.docx');

$template->setValue('Name','你好,测试-123abc');//${Name}

$template->setValue('Street', 'Coming-Undone-Street 32');

$filename = 'PHPWord/mb/test_update.docx';

$template->save($filename);

2.直接创建表格$section = $PHPWord->createSection();

$styleTable = array('borderSize'=>6, 'borderColor'=>'000000', 'cellMargin'=>80);//表格样式

$fontStyle = array('bold'=>true, 'align'=>'center');//文字样式

$PHPWord->addTableStyle('table_1', $styleTable);//定义表格样式

$table = $section->addTable('table_1');

$table->addRow(400);

$table->addCell(2000)->addText('Cell 1',$fontStyle);

$table->addCell(2000)->addText('Cell 2',$fontStyle);

$table->addCell(2000)->addText('Cell 3',$fontStyle);

$table->addRow(1000);

$table->addCell(2000)->addText('Cell 4',$fontStyle);

$table->addCell(2000)->addText('Cell 5',$fontStyle);

$table->addCell(2000)->addText('Cell 6',$fontStyle);

$objWrite = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');

$filename = 'PHPWord/mb/test_create.docx';

$objWrite->save($filename);

3.PHPWord插件文件及中文技术文档下载


版权声明:本文为weixin_33754744原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。