## 采用 PhpPresentation 插件生成PPT
下载方式 composer , composer.json里面增加, 然后 composer update
```
"require": {
"phpoffice/phppresentation": "dev-master"
},
```
git 地址: [https://github.com/PHPOffice/PHPPresentation](https://link.jianshu.com/?t=https%3A%2F%2Fgithub.com%2FPHPOffice%2FPHPPresentation)
手册地址:[http://phppowerpoint.readthedocs.io/en/latest/](https://link.jianshu.com/?t=http%3A%2F%2Fphppowerpoint.readthedocs.io%2Fen%2Flatest%2F)
demo
```
~~~
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Alignment;
class PhpOffice1
{
public function index()
{
// 2.创建ppt对象
$objPHPPowerPoint = new PhpPresentation();
// 3.设置属性
$objPHPPowerPoint->getDocumentProperties()->setCreator('PHPOffice')
->setLastModifiedBy('PHPPresentation Team')
->setTitle('Sample 02 Title')
->setSubject('Sample 02 Subject')
->setDescription('Sample 02 Description')
->setKeywords('office 2007 openxml libreoffice odt php')
->setCategory('Sample Category');
// 4.删除第一页(多页最好删除)
$objPHPPowerPoint->removeSlideByIndex(0);
//根据需求 调整for循环
for ($i = 1; $i <= 3; $i++) {
//创建幻灯片并添加到这个演示中
$slide = $objPHPPowerPoint->createSlide();
//创建一个形状(图)
$shape = $slide->createDrawingShape();
$shape->setName('内容图片name')
->setDescription('内容图片 描述')
->setPath(WEB_PATH . '/uploads/img/background.jpg')
->setResizeProportional(false)
->setHeight(720)
->setWidth(960);
//创建一个形状(文本)
$shape = $slide->createRichTextShape()
->setHeight(60)
->setWidth(960)
->setOffsetX(10)
->setOffsetY(50);
$shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_CENTER);
$textRun = $shape->createTextRun('以后这个就是标题了');
$textRun->getFont()->setBold(true)
->setSize(20)
->setColor(new Color('FFE06B20'));
// 创建一个形状(文本)
$shape = $slide->createRichTextShape()
->setHeight(60)
->setWidth(960)
->setOffsetX()
->setOffsetY(700);
$shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_RIGHT);
$textRun = $shape->createTextRun('时间:2017年10月19号');
$textRun->getFont()->setBold(true)
->setSize(10)
->setColor(new Color('FFE06B20'));
}
$oWriterPPTX = IOFactory::createWriter($objPHPPowerPoint, 'PowerPoint2007');
//路径 /uploads/ppt/ 必须存在
$url = WEB_PATH . "/uploads/ppt/" . time() . ".pptx";
//生成PPT
$oWriterPPTX->save($url);
//下载PPT
download($url);
//删除PPT
deldir($url);
exit;
}
}
function download($file)
{
if(file_exists($file)){
header("Content-type:application/octet-stream");
$filename = basename($file);
header("Content-Disposition:attachment;filename = ".$filename);
header("Accept-ranges:bytes");
header("Accept-length:".filesize($file));
readfile($file);
}else{
echo "<script>alert('文件不存在')</script>";
}
}
//删除文件
function deldir($dir)
{
unlink($dir);
closedir($dir);
}
~~~
```
- ThinkPHP
- MySql
- 事务
- 漏洞修复
- jQuery
- select搜索下拉框,多选,全选等
- 移动端富文本编辑器
- 复制内容
- ajax请求
- PHP
- 基本语法
- 关于屏蔽“未定义数组下标:0”错误的问题
- PHP文件操作
- 使用PhpOffice 在PHP7.3中导出数据报错问题
- curl
- PHP生成PPT
- Redis
- 如何在PHP中安装Redis扩展
- Redis队列,秒杀,抢购
- 压力测试(ab)
- apache ab压力测试
- 微信
- 微信支付
- 微信分享
- 授权登录
- 微信公众号服务器
- 自动回复
- 微信发起支付html页面
- composer
- 安装
- 二维码的生成
- Excel导入导出
- 数据采集
- 采集列表
- 采集内容详情
- 图片采集
- Linux
- 常用命令
- 解压压缩
- 服务器
- 服务器运行缓慢的原因
- IIS 隐藏index.php
- 端口检测
- Nginx
- 数据库
- Oracle数据库
- MySql
- 新增MySql
- Field字段
- Tp验证码加载不出来,解决办法
- API接口
- Google API
- 织梦CMS支付接口
- SMTP发送邮箱问题
- Could not connect to SMTP host
- 阿里云API接口
- 支付宝新版配置
- 腾讯API接口
- 安装方法
- 百度地图API
- 通过ip地址获取当前城市
- 常用笔记
- yarn