Home  >  Article  >  Backend Development  >  Analysis of Examples of Creating PPT Documents with PHP_PHP Tutorial

Analysis of Examples of Creating PPT Documents with PHP_PHP Tutorial

WBOY
WBOYOriginal
2016-07-15 13:35:061237browse

Code example for creating PPT document with PHP:

  1. < ?php
  2. / *** PHP generates PowerPoint 2007 sample script.
    * * This program requires PHP 5.2 or above,
    requires php_zip and
    php_xml extension support.
  3. * Usually under WIN The program only needs to open the php_zip extension.
    The php_xml extension has built-in support.
  4. * Under Linux, specific adjustments need to be made according to the compilation conditions.
  5. * * @author: Guya
  6. * @since: 2009-4-30
  7. */
  8. //Directory separation symbol
  9. define('DS', DIRECTORY_SEPARATOR);
  10. //Define the root directory
  11. define('ROOT', dirname(__FILE__) . DS);
  12. //Modify the include path, PHPPowerPoint
    package is placed in the libs directory of the current directory.
  13. set_include_path(get_include_path() .
    PATH_SEPARATOR . ROOT . 'libs');
  14. //No limit on script running time.
  15. set_time_limit(0);
  16. //Simple setting of autoload function.
  17. function __autoload($className)
    { include_once(str_replace("_", DS,
     $className) . ".php"); }
  18. //Create a new PHPPowerPoint object.
  19. $ppp = new PHPPowerPoint();
  20. //Get the currently used slideshow
  21. $activeSlide = $ppp->getActiveSlide();
  22. //Add a picture to the slide. >
  23. shape
  24. = $activeSlide->createDrawingShape() ; //Set the image name.
  25. $shape-
  26. >setName('MmClub.net Logo'); //Set the description information of the picture. 🎜>$shape-
  27. >
  28. setDescription('MmClub.net Logo'); //The actual path of the image $shape-
  29. >
  30. setPath (ROOT . 'mmclub.net.jpg'); //Picture height $shape-
  31. >
  32. setHeight(103); //Set image width $shape-
  33. >
  34. setWidth(339); / /Set the X position of the picture relative to the upper left corner, unit pixel $shape-
  35. >
  36. setOffsetX(10); //Set the Y position of the image relative to the upper left corner, unit pixels $shape-
  37. >
  38. setOffsetY(10); $shape->
  39. getShadow()-
  40. >
  41. setVisible(true); >getShadow()->setDirection(45);
  42. $shape-
  43. >getShadow()- >setDistance(10);
  44. //Set a text box
  45. $shape = $activeSlide->createRichTextShape();
  46. //Set text box height, unit pixels
  47. $shape->setHeight(150); //Set the text box width in pixels
  48. $shape-
  49. >
  50. setWidth(600); //Set the X position of the text box relative to the upper left corner, unit pixels
  51. $shape-
  52. >
  53. setOffsetX(150); //Set the Y position of the text box relative to the upper left corner, unit pixels
  54. $shape-
  55. >
  56. setOffsetY(200);
  57. //Set the text layout position to be horizontally centered and vertically centered.
  58. $shape->getAlignment()->setHorizontal(
    PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER ) ;
  59. $shape->getAlignment()->setVertical(
    PHPPowerPoint_Style_Alignment::VERTICAL_CENTER );
  60. //Set the text box Text content. There is no Chinese problem when testing in a Chinese environment.
    If in an e-text environment, be sure to specify a font that supports Chinese.
    Otherwise, garbled characters may appear.
  61. $textRun = $shape-> createTextRun(
    'Welcome to PHPPowerPoint2007');
  62. //Use font bold
  63. $textRun->getFont()->setBold(true);
  64. //Set the font size to 38, pay attention to the text size setting here.
    The size of the previous text box is fixed. If the text exceeds The
    container will be out of the container and queued to the bottom
  65. $textRun->getFont()->setSize(38);
  66. //Set text color, here is ARGB mode, hexadecimal mode,
    The first 2 digits are transparency, and the back is RGB value. Here is set to blue
  67. $ textRun->getFont()->setColor( new
    PHPPowerPoint_Style_Color( 'FFFF0000' ) );
  68. //Set a few more text boxes below
  69. $shape0 = $activeSlide->createRichTextShape(); setHeight(50);
  70. $shape0->setWidth(400) ;
  71. $shape0->setOffsetX(250);
  72. $shape0->setOffsetY(400);
  73. $shape0->getAlignment()-
  74. >setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER ); $shape0->
    getAlignment()-
  75. >setVertical ( PHPPowerPoint_Style_Alignment::VERTICAL_CENTER ); $textRun0 = $shape0-
  76. >
  77. createTextRun('http://www.mmclub.net');   
  78. $textRun0->getFont()->setSize(26);   
  79. $textRun0->getFont()->setColor( new 
    PHPPowerPoint_Style_Color( 'FF0000FF' ) );   
  80. $shape1 = $activeSlide->createRichTextShape();   
  81. $shape1->setHeight(30);   
  82. $shape1->setWidth(200);  
  83.  $shape1->setOffsetX(700);   
  84. $shape1->setOffsetY(500);   
  85. $shape1->getAlignment()->setHorizontal( 
    PHPPowerPoint_Style_Alignment::HORIZONTAL_LEFT ); 
  86. $shape1->getAlignment()->setVertical( 
    PHPPowerPoint_Style_Alignment::VERTICAL_CENTER ); 
  87. $textRun1 = $shape1->createTextRun('Author: Guya'); 
  88. $textRun1->getFont()->setSize(14);  
  89.  $textRun1->getFont()->setColor( new 
    PHPPowerPoint_Style_Color( 'FF000000' ) );   
  90. $shape2 = $activeSlide->createRichTextShape();  
  91.  $shape2->setHeight(30);  
  92.  $shape2->setWidth(200);  
  93.  $shape2->setOffsetX(700);   
  94. $shape2->setOffsetY(540); $shape2->getAlignment()->
    setHorizontal( PHPPowerPoint_Style_Alignment::
    HORIZONTAL_LEFT ); 
  95. $shape2->getAlignment()->setVertical( 
    PHPPowerPoint_Style_Alignment::VERTICAL_CENTER );
  96. $textRun2 = $shape2->createTextRun('Date: 2009-4-30');
  97. $textRun2->getFont()->setSize(14);
  98. $textRun2->getFont( )->setColor(
    new PHPPowerPoint_Style_Color( 'FF000000' ) );
  99. //Save PPTX file, using 2007 format
  100. $objWriter = PHPPowerPoint_IOFactory::
    createWriter($ppp, 'PowerPoint2007');
  101. //Save the file
  102. $objWriter->save(ROOT . 'myPhpPpt.pptx');
  103. echo 'ppt create success!'; >
  104. As for the application prospects of creating PPT documents with PHP, it is still very useful in some WEB situations. Friends who need it can spend more time to study it. http://www.bkjia.com/PHPjc/445942.html
  105. www.bkjia.com

true


http: //www.bkjia.com/PHPjc/445942.html

TechArticle

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn