PHP 生成 ppt,PhpPresentation生成ppt
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');
}
總結
以上是生活随笔為你收集整理的PHP 生成 ppt,PhpPresentation生成ppt的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java集合框架讲解【泛型、Collec
- 下一篇: SELECT命令中的GROUPBY和HA