This article describes the method of creating PowerPoint2007 documents by PHP. Share it for your reference, as follows:
This morning I saw a very interesting article from the subscribed Zend DevZone. I tried it. It was really interesting, so I will share it with you.
The program requires PHP 5.2 or above, and also requires the support of php_zip and php_xml extension modules. In addition, you need to download the PHPPowerPoint class library. Official website address:/The current stable version is 0.1.0. You can also click hereDownload this site。
Let me tell you what it feels. This class library is OK. The encoding is very standardized. It is completely PHP5 style. The type I like. It is the same as the Zend Framework. The processing speed is also very fast. This time I only tested it simply. I didn’t take time to play with more advanced features. Please post the test code.
<?php /** * PHP generates PowerPoint 2007 sample script. * * This program requires PHP 5.2 or above, and requires php_zip and php_xml extension support. * Usually, programs under WIN only need to open the php_zip extension, and the php_xml extension is built-in support. * In Linux, it needs to be adjusted according to the compilation conditions. * * @author: Guya * @since: 2009-4-30 */ //Directory segmentation symboldefine('DS', DIRECTORY_SEPARATOR); //Define the root directorydefine('ROOT', dirname(__FILE__) . DS); //Modify the include path, and place the PHPPowerPoint package in the libs directory of the current directory.set_include_path(get_include_path() . PATH_SEPARATOR . ROOT . 'libs'); //No script run time limit is restricted.set_time_limit(0); //Simplely set the automatic loading function.function __autoload($className) { include_once(str_replace("_", DS, $className) . ".php"); } // Create a new PHPPowerPoint object.$ppp = new PHPPowerPoint(); //Get the currently used one-page slide$activeSlide = $ppp->getActiveSlide(); //Add a picture to the slide.$shape = $activeSlide->createDrawingShape(); //Set the picture name.$shape->setName(' Logo'); //Set the description information of the picture.$shape->setDescription(' Logo'); //The actual path of the picture$shape->setPath(ROOT . ''); //Picture height$shape->setHeight(103); //Set the image width$shape->setWidth(339); //Set the X position of the picture relative to the upper left corner, unit pixels$shape->setOffsetX(10); //Set the Y position of the picture relative to the upper left corner, unit pixels$shape->setOffsetY(10); //Set the picture display status$shape->getShadow()->setVisible(true); $shape->getShadow()->setDirection(45); $shape->getShadow()->setDistance(10); //Set a text box$shape = $activeSlide->createRichTextShape(); //Set the text box height, unit pixels$shape->setHeight(150); //Set the text box width, unit pixels$shape->setWidth(600); //Set the X position of the text box relative to the upper left corner, unit pixels$shape->setOffsetX(150); //Set the Y position of the text box relative to the upper left corner, unit pixels$shape->setOffsetY(200); //Set the text layout position to be horizontally centered and vertically centered.$shape->getAlignment()->setHorizontal( PHPPowerPoint_Style_Alignment::HORIZONTAL_CENTER ); $shape->getAlignment()->setVertical( PHPPowerPoint_Style_Alignment::VERTICAL_CENTER ); //Set the text content of the text box. Test without Chinese problems in the Chinese environment. If in the e-text environment, be careful to specify fonts that support Chinese. Otherwise, garbled code may appear.$textRun = $shape->createTextRun('Welcome to PHPPowerPoint2007'); // Use font to thicken$textRun->getFont()->setBold(true); //Set the font size to 38, please pay attention to the size setting of the text here. The size of the text box in the front is fixed. If the container with excessive text will be out of the container and will be placed below$textRun->getFont()->setSize(38); //Set the text color, here is ARGB mode, hexadecimal mode, the first 2 digits are transparent, and the following is RGB value. Here is set to blue blue$textRun->getFont()->setColor( new PHPPowerPoint_Style_Color( 'FFFF0000' ) ); // Set a few text boxes below$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://'); $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' ) ); //Save PPTX file, use 2007 format$objWriter = PHPPowerPoint_IOFactory::createWriter($ppp, 'PowerPoint2007'); //Save the file$objWriter->save(ROOT . ''); echo 'ppt create success!'; ?>
If the application prospects of this thing are still very useful in some WEB occasions. Friends who need it can spend more time researching it
I hope this article will be helpful to everyone's PHP programming.