require_once 'PHPWord.php';
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
//添加页眉
$header = $section->createHeader();
$table = $header->addTable();
$table->addRow();
$table->addCell(4500)->addText('This is the header');
$table->addCell(4500)->addImage('_earth.jpg',array('width'=>50,'height'=>50,'align'=>'right'));
//添加页脚
$footer = $section->createFooter();
$footer->addPreserveText('Page {PAGE} of {NUMPAGES}.',array('align'=>'center'));
//添加一些文本
$section->addTextBreak();
$section->addText('Some Text ...');
//保存文件
$objWriter = PHPWord_IOFactory::createWriter($PHPWord,'Word2007');
$objWriter->save('HeaderFooter.docx');
【PHPWord】页眉与页脚
最新推荐文章于 2025-07-01 00:38:30 发布