require_once 'PHPWord.php';
$PHPWord = new PHPWord();
$section = $PHPWord->createSection();
//定义TOC字体样式
$fontStyle = array('spaceAfter'=>60,'size'=>12);
//添加标题样式
$PHPWord->addTitleStyle(1,array('size'=>20,'color'=>'333333','bold'=>true));
$PHPWord->addTitleStyle(2,array('size'=>16,'color'=>'66666'));
//添加文本
$section->addText('Table of contents:');
$section->addTextBreak(2);
//添加TOC
$section->addToc($fontStyle);
//添加标题
$section->addPageBreak();
$section->addTitle('This is the title');
$section->addText('Some text...');
$section->addTextBreak(2);
$section->addTitle('I am a Subtitle of Title 1',2);
$section->addTextBreak(2);
$section->addText('Some More text...');
$section->addTextBreak(2);
$section->addTitle('Anoter Title (Title 2)',1);
$section->addText('Some text...');
$section->addTextBreak(2);
$section->addTitle('I am Title 3',1);
$section->addText('And more text...');
$section->addTextBreak(2);
$section->addTitle('I am a Subtitle of Title 3',2);
$section->addText('Again and Again, More text...');
//保存文件
$objWriter = PHPWord_IOFactory::createWriter($PHPWord,'Word2007');
$objWriter->save('TitleTOC.docx');
?>【PHPWord】TitleTOC
最新推荐文章于 2023-06-01 18:08:08 发布
本文将指导您如何使用PHPWord库为Word文档创建目录及自定义标题样式,包括添加目录、设置标题字体、颜色和大小,以及在文档中插入页眉和页脚。
1621

被折叠的 条评论
为什么被折叠?



