温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

PHP怎么创建PPT文档

发布时间:2021-07-19 11:39:39 来源:亿速云 阅读:123 作者:chen 栏目:编程语言

本篇内容介绍了“PHP怎么创建PPT文档”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

PHP功能非常强大,目前被许多程序员用来WEB开发。它可以方便灵活的帮助我们实现许多功能。比如今天我们要为大家介绍的PHP创建PPT文档的技巧。

  • PHP操作Cookie相关技巧分享

  • PHP Cookie登录验证技巧讲解

  • 深入解读PHP删除Cookie技巧

  • PHP函数restore()重置PHP配置环境

  • PHP数据缓存类必要性分析

PHP创建PPT文档代码实例:

  1. < ?php   

  2. /** * PHP 生成 PowerPoint 2007 示例脚本.
     * * 本程序需要 PHP 5.2 以上版本, 
    需要 php_zip 和 
    php_xml 扩展支持. 

  3. * 通常WIN下程序只要打开 php_zip 扩展即可, 
    php_xml 扩展内置支持. 

  4. * Linux 下需要根据编译条件具体调整. 

  5. * * @author: Guya 

  6. * @since: 2009-4-30 

  7. */   

  8. //目录分割符号   

  9. define('DS', DIRECTORY_SEPARATOR);   

  10. //定义根目录   

  11. define('ROOT', dirname(__FILE__) . DS);  

  12.  //修改include路径, PHPPowerPoint 
    包放在当前目录的 libs 目录下.   

  13. set_include_path(get_include_path() . 
    PATH_SEPARATOR . ROOT . 'libs');   

  14. //不限制脚本运行时间限制.   

  15. set_time_limit(0);   

  16. //简单设置自动载入函数.   

  17. function __autoload($className)
     { include_once(str_replace("_", DS,
     $className) . ".php"); }   

  18. //新建立一个 PHPPowerPoint 对象.   

  19. $ppp = new PHPPowerPoint();   

  20. //获取当前使用的一页幻灯片   

  21. $activeSlide = $ppp->getActiveSlide();   

  22. //添加一个图片到幻灯片.   

  23. $shape = $activeSlide->createDrawingShape();   

  24. //设置图片名称.   

  25. $shape->setName('MmClub.net Logo');   

  26. //设置图片的描述信息.   

  27. $shape->setDescription('MmClub.net Logo');   

  28. //图片实际路径   

  29. $shape->setPath(ROOT . 'mmclub.net.jpg');   

  30. //图片高度   

  31. $shape->setHeight(103);   

  32. //设置图片宽度   

  33. $shape->setWidth(339);   

  34. //设置图片相对于左上角X位置, 单位像素   

  35. $shape->setOffsetX(10);   

  36. //设置图片相对于左上角Y位置, 单位像素   

  37. $shape->setOffsetY(10);   

  38. //设置图显示状态   

  39. $shape->getShadow()->setVisible(true);   

  40. $shape->getShadow()->setDirection(45);   

  41. $shape->getShadow()->setDistance(10);   

  42. //设置一个文本框   

  43. $shape = $activeSlide->createRichTextShape();   

  44. //设置文本框高度, 单位像素   

  45. $shape->setHeight(150);   

  46. //设置文本框宽度, 单位像素  

  47.  $shape->setWidth(600);   

  48. //设置文本框相对于左上角X位置, 单位像素   

  49. $shape->setOffsetX(150);   

  50. //设置文本框相对于左上角Y位置, 单位像素   

  51. $shape->setOffsetY(200);   

  52. //设置文本布局位置为水平居中, 垂直居中.   

  53. $shape->getAlignment()->setHorizontal(
     PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER );  

  54. $shape->getAlignment()->setVertical(
     PHPPowerPoint_Style_Alignment::VERTICAL_CENTER );   

  55. //设置文本框文本内容. 在中文环境下测试没中文问题.
     如果在 e 文环境. 注意要指定支持中文的字体. 
    否则可能出乱码了.   

  56. $textRun = $shape->createTextRun(
    '欢迎使用 PHPPowerPoint2007');   

  57. //使用字体加粗   

  58. $textRun->getFont()->setBold(true);   

  59. //设置字体尺寸为 38, 这里注意一下文字的大小设置. 
    前面的文本框的大小是固定的. 如果文字超出的
    容器会被出容器被排到下面   

  60. $textRun->getFont()->setSize(38);   

  61. //设置文字颜色, 这里是ARGB模式 , 16进制模式, 
    前面2位为透明度, 后面为RGB值. 这里设置为 blue蓝色   

  62. $textRun->getFont()->setColor( new 
    PHPPowerPoint_Style_Color( 'FFFF0000' ) );   

  63. //下面再设置几个文本框   

  64. $shape0 = $activeSlide->createRichTextShape();   

  65. $shape0->setHeight(50);   

  66. $shape0->setWidth(400);  

  67.  $shape0->setOffsetX(250);   

  68. $shape0->setOffsetY(400);   

  69. $shape0->getAlignment()->setHorizontal(
     PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER ); 

  70. $shape0->getAlignment()->setVertical
    ( PHPPowerPoint_Style_Alignment::VERTICAL_CENTER ); 

  71. $textRun0 = $shape0->createTextRun('http:
    //www.mmclub.net');   

  72. $textRun0->getFont()->setSize(26);   

  73. $textRun0->getFont()->setColor( new 
    PHPPowerPoint_Style_Color( 'FF0000FF' ) );   

  74. $shape1 = $activeSlide->createRichTextShape();   

  75. $shape1->setHeight(30);   

  76. $shape1->setWidth(200);  

  77.  $shape1->setOffsetX(700);   

  78. $shape1->setOffsetY(500);   

  79. $shape1->getAlignment()->setHorizontal( 
    PHPPowerPoint_Style_Alignment::HORIZONTAL_LEFT ); 

  80. $shape1->getAlignment()->setVertical( 
    PHPPowerPoint_Style_Alignment::VERTICAL_CENTER ); 

  81. $textRun1 = $shape1->createTextRun('Author: Guya'); 

  82. $textRun1->getFont()->setSize(14);  

  83.  $textRun1->getFont()->setColor( new 
    PHPPowerPoint_Style_Color( 'FF000000' ) );   

  84. $shape2 = $activeSlide->createRichTextShape();  

  85.  $shape2->setHeight(30);  

  86.  $shape2->setWidth(200);  

  87.  $shape2->setOffsetX(700);   

  88. $shape2->setOffsetY(540); $shape2->getAlignment()->
    setHorizontal( PHPPowerPoint_Style_Alignment::
    HORIZONTAL_LEFT ); 

  89. $shape2->getAlignment()->setVertical( 
    PHPPowerPoint_Style_Alignment::VERTICAL_CENTER ); 

  90. $textRun2 = $shape2->createTextRun('Date: 2009-4-30'); 

  91. $textRun2->getFont()->setSize(14);   

  92. $textRun2->getFont()->setColor( 
    new PHPPowerPoint_Style_Color( 'FF000000' ) );  

  93.  //保存PPTX 文件, 使用 2007 格式   

  94. $objWriter = PHPPowerPoint_IOFactory::
    createWriter($ppp, 'PowerPoint2007');   

  95. //保存文件   

  96. $objWriter->save(ROOT . 'myPhpPpt.pptx');   

  97. echo 'ppt create success!';   

  98. ?>  

这个PHP创建PPT文档的应用前景的话. 在WEB的某些场合还是很有用的. 需要的朋友可以多花点时间去研究了.

“PHP怎么创建PPT文档”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php
AI