这篇文章主要讲解了“PHP怎么创建PowerPoint2007文档”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“PHP怎么创建PowerPoint2007文档”吧!
本文实例讲述了PHP创建PowerPoint2007文档的方法。分享给大家供大家参考,具体如下:
<?php
/**
* PHP 生成 PowerPoint 2007 示例脚本.
*
* 本程序需要 PHP 5.2 以上版本, 需要 php_zip 和 php_xml 扩展支持.
* 通常WIN下程序只要打开 php_zip 扩展即可, php_xml 扩展内置支持.
* Linux 下需要根据编译条件具体调整.
*
* @author: Guya
* @since: 2009-4-30
*/
//目录分割符号
define('DS', DIRECTORY_SEPARATOR);
//定义根目录
define('ROOT', dirname(__FILE__) . DS);
//修改include路径, PHPPowerPoint 包放在当前目录的 libs 目录下.
set_include_path(get_include_path() . PATH_SEPARATOR . ROOT . 'libs');
//不限制脚本运行时间限制.
set_time_limit(0);
//简单设置自动载入函数.
function __autoload($className) {
include_once(str_replace("_", DS, $className) . ".php");
}
//新建立一个 PHPPowerPoint 对象.
$ppp = new PHPPowerPoint();
//获取当前使用的一页幻灯片
$activeSlide = $ppp->getActiveSlide();
//添加一个图片到幻灯片.
$shape = $activeSlide->createDrawingShape();
//设置图片名称.
$shape->setName('MmClub.net Logo');
//设置图片的描述信息.
$shape->setDescription('MmClub.net Logo');
//图片实际路径
$shape->setPath(ROOT . 'mmclub.net.jpg');
//图片高度
$shape->setHeight(103);
//设置图片宽度
$shape->setWidth(339);
//设置图片相对于左上角X位置, 单位像素
$shape->setOffsetX(10);
//设置图片相对于左上角Y位置, 单位像素
$shape->setOffsetY(10);
//设置图显示状态
$shape->getShadow()->setVisible(true);
$shape->getShadow()->setDirection(45);
$shape->getShadow()->setDistance(10);
//设置一个文本框
$shape = $activeSlide->createRichTextShape();
//设置文本框高度, 单位像素
$shape->setHeight(150);
//设置文本框宽度, 单位像素
$shape->setWidth(600);
//设置文本框相对于左上角X位置, 单位像素
$shape->setOffsetX(150);
//设置文本框相对于左上角Y位置, 单位像素
$shape->setOffsetY(200);
//设置文本布局位置为水平居中, 垂直居中.
$shape->getAlignment()->setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER );
$shape->getAlignment()->setVertical( PHPPowerPoint_Style_Alignment::VERTICAL_CENTER );
//设置文本框文本内容. 在中文环境下测试没中文问题. 如果在 e 文环境. 注意要指定支持中文的字体. 否则可能出乱码了.
$textRun = $shape->createTextRun('欢迎使用 PHPPowerPoint2007');
//使用字体加粗
$textRun->getFont()->setBold(true);
//设置字体尺寸为 38, 这里注意一下文字的大小设置. 前面的文本框的大小是固定的. 如果文字超出的容器会被出容器被排到下面
$textRun->getFont()->setSize(38);
//设置文字颜色, 这里是ARGB模式 , 16进制模式, 前面2位为透明度, 后面为RGB值. 这里设置为 blue蓝色
$textRun->getFont()->setColor( new PHPPowerPoint_Style_Color( 'FFFF0000' ) );
//下面再设置几个文本框
$shape0 = $activeSlide->createRichTextShape();
$shape0->setHeight(50);
$shape0->setWidth(400);
$shape0->setOffsetX(250);
$shape0->setOffsetY(400);
$shape0->getAlignment()->setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER );
$shape0->getAlignment()->setVertical( PHPPowerPoint_Style_Alignment::VERTICAL_CENTER );
$textRun0 = $shape0->createTextRun('https://www.jb51.net');
$textRun0->getFont()->setSize(26);
$textRun0->getFont()->setColor( new PHPPowerPoint_Style_Color( 'FF0000FF' ) );
$shape1 = $activeSlide->createRichTextShape();
$shape1->setHeight(30);
$shape1->setWidth(200);
$shape1->setOffsetX(700);
$shape1->setOffsetY(500);
$shape1->getAlignment()->setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_LEFT );
$shape1->getAlignment()->setVertical( PHPPowerPoint_Style_Alignment::VERTICAL_CENTER );
$textRun1 = $shape1->createTextRun('Author: Guya');
$textRun1->getFont()->setSize(14);
$textRun1->getFont()->setColor( new PHPPowerPoint_Style_Color( 'FF000000' ) );
$shape2 = $activeSlide->createRichTextShape();
$shape2->setHeight(30);
$shape2->setWidth(200);
$shape2->setOffsetX(700);
$shape2->setOffsetY(540);
$shape2->getAlignment()->setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_LEFT );
$shape2->getAlignment()->setVertical( PHPPowerPoint_Style_Alignment::VERTICAL_CENTER );
$textRun2 = $shape2->createTextRun('Date: 2009-4-30');
$textRun2->getFont()->setSize(14);
$textRun2->getFont()->setColor( new PHPPowerPoint_Style_Color( 'FF000000' ) );
//保存PPTX 文件, 使用 2007 格式
$objWriter = PHPPowerPoint_IOFactory::createWriter($ppp, 'PowerPoint2007');
//保存文件
$objWriter->save(ROOT . 'myPhpPpt.pptx');
echo 'ppt create success!';
?>
感谢各位的阅读,以上就是“PHP怎么创建PowerPoint2007文档”的内容了,经过本文的学习后,相信大家对PHP怎么创建PowerPoint2007文档这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。