public function toPPT() {
$objPHPPresentation = new PhpPresentation(); //创建对象
$objPHPPresentation->getLayout()->setDocumentLayout(DocumentLayout::LAYOUT_B5ISO); //设置ppt比例
//也可以自定义宽高
//$objPHPPresentation->getLayout()->setCX( 1450, DocumentLayout::UNIT_PIXEL)->setCY( 800,DocumentLayout::UNIT_PIXEL);
$currentSlide = $objPHPPresentation->getActiveSlide(); //获取第一张幻灯片
//设置PPT背景图片
$imgPath = '';
$oBackground = new \PhpOffice\PhpPresentation\Slide\Background\Image();
$oBackground->setPath($imgPath);
$currentSlide->setBackground($oBackground);
//添加一个文本框
$shape = $currentSlide->createRichTextShape()
->setHeight(50) //高
->setWidth(50) //宽
->setOffsetX(50) //X轴偏移量
->setOffsetY(50); //Y轴偏移量
//设置文本框样式
$shape->getBorder()
->setLineStyle(\PhpOffice\PhpPresentation\Style\Border::LINE_SINGLE) //单行线
->setLineWidth(2) //宽度
->setDashStyle(\PhpOffice\PhpPresentation\Style\Border::DASH_SYSDASH) //虚线
->getColor()->setARGB(\PhpOffice\PhpPresentation\Style\Color::COLOR_DARKBLUE); //颜色
//->setColor(new \PhpOffice\PhpPresentation\Style\Color::COLOR_DARKBLUE);
//设置文本框内字体
$shape->getActiveParagraph()->getAlignment()->setHorizontal( \PhpOffice\PhpPresentation\Style\Alignment::HORIZONTAL_LEFT ); //偏左 居中 偏右
$textRun = $shape->createTextRun('这是你要写的文字');
$textRun->getFont()
->setBold(true) //是否加粗
->setSize(34) //字体大小
->setName('微软雅黑') //字体样式
->setColor( new \PhpOffice\PhpPresentation\Style\Color('FFFF0000') ); //字体颜色
//添加一张图片
$shape = $currentSlide->createDrawingShape();
$img = '';
$shape->setPath($img)
->setHeight(40)
->setWidth(40)
->setOffsetX(40) //X轴偏移量
->setOffsetY(40); //Y轴偏移量
$shape->getShadow()->setVisible(true); //这句话没有具体研究,图片样式,如果需要,自行看源代码
//再新建一张幻灯片
$currentSlide = $objPHPPresentation->createSlide();
//保存 如果上面是自定义PPT宽高 请不要加第二个参数
$oWriterPPTX = \PhpOffice\PhpPresentation\IOFactory::createWriter($objPHPPresentation,'PowerPoint2007');
$oWriterPPTX->save('fileName');
}