Php method for reading PPT files

Source: Internet
Author: User
Tags echo date php programming
This article explains how PHP reads ppt files. Share to everyone for your reference, as follows:

Recently do a flash related things, which will be used in the Web site to see ppt like Baidu, bean ding nets can be directly on the website to read, search on the internet for a long time did not search, are what installed a software what, PHP site put on the space, who can let you where to install software? Isn't that a nonsense? But fortunately, finally in a foreign site found a solution, is a PHP operation PPT class, of course, this site also provides the operation of offices software other classes, but the 2007 version of the offices, is now posted to the Web site dedicated to everyone:/http phppowerpoint.codeplex.com/. You can also click here to download the site.

This class can implement read/write/generate in PPT2007 format

Here is an example of what I saw at the time:

This example uses the Phppowerpoint class, using this class to note two points, one is to understand the meaning of the parameter, the second note character set

<?phpheader ("Content-type:text/html;charset=utf-8");//font settings prevent garbled error_reporting (e_all);/** Include Path **/set_ Include_path (Get_include_path (). Path_separator. '.. /classes/');/** phppowerpoint */include ' phppowerpoint.php ';/** phppowerpoint_iofactory */include ' PHPPowerPoint/ Iofactory.php ';//Create new Phppowerpoint Object//echo date (' H:i:s '). "Create new Phppowerpoint object\n"; $objPHPPowerPoint = new Phppowerpoint (); $objPHPPowerPoint->getproperties ()- >setcreator ("Maarten Balliauw"), $objPHPPowerPoint->getproperties ()->setlastmodifiedby ("Maarten Balliauw "); $objPHPPowerPoint->getproperties ()->settitle (" Office "PPTX Test Document"), $objPHPPowerPoint GetProperties ()->setsubject ("Office" PPTX Test Document "), $objPHPPowerPoint->getproperties () SetDescription ("Test Document for Office page PPTX, generated using PHP classes."); $objPHPPowerPoint->getproperties ()->setkeywords ("Office openxml PHP"), $objPHPPowerPoint GetProperties ()-> Setcategory ("Test result file");//Remove First Slide//echo date (' H:i:s '). "Remove first slide\n"; $objPHPPowerPoint->removeslidebyindex (0);//Create Templated Slide//echo date (' H:i:s '). "Create templated slide\n";/* $currentSlide = Createtemplatedslide ($objPHPPowerPoint); Local function//Create a shape (text) echo date (' H:i:s '). "Create a shape (rich text) \ n"; $shape = $currentSlide->createrichtextshape (); $shape->setheight (+); $shape- >setwidth, $shape->setoffsetx (), $shape->setoffsety, $shape->getalignment () Sethorizontal (phppowerpoint_style_alignment::horizontal_left); $textRun = $shape->createtextrun (' Introduction To '); $textRun->getfont ()->setbold (true), $textRun->getfont ()->setsize (), $textRun->getfont ()- >setcolor (New Phppowerpoint_style_color (' FFFFFFFF ')); $shape->createbreak (); $textRun = $shape Createtextrun (' Phppowerpoint '); $textRun->getfont ()->setbold (true); $textRun->getfont ()->setsize (60) ; $teXtrun->getfont ()->setcolor (New Phppowerpoint_style_color (' FFFFFFFF '));//Create Templated Slideecho date (' H:i : S '). "Create templated slide\n"; $currentSlide = Createtemplatedslide ($objPHPPowerPoint); Local function//Create a shape (text) echo date (' H:i:s '). "Create a shape (rich text) \ n"; $shape = $currentSlide->createrichtextshape (); $shape->setheight (+); $shape- >setwidth (930), $shape->setoffsetx (Ten), $shape->setoffsety ($shape->getalignment (), Sethorizontal (phppowerpoint_style_alignment::horizontal_left); $textRun = $shape->createtextrun (' What's Phppowerpoint? '); $textRun->getfont ()->setbold (true), $textRun->getfont ()->setsize (), $textRun->getfont () SetColor (New Phppowerpoint_style_color (' FFFFFFFF '));//Create a shape (text) echo date (' H:i:s '). "Create a shape (rich text) \ n"; $shape = $currentSlide->createrichtextshape (); $shape->setheight (+); $shape- >setwidth (930), $shape->setoffsetx (), $shape->setoffsety$shape->getalignment ()->sethorizontal (phppowerpoint_style_alignment::horizontal_left); $textRun = $ Shape->createtextrun ('-A class library '), $textRun->getfont ()->setsize (), $textRun->getfont () SetColor (New Phppowerpoint_style_color (' FFFFFFFF ')); $shape->createbreak (); $textRun = $shape->createtextrun ( '-Written in PHP '); $textRun->getfont ()->setsize; $textRun->getfont ()->setcolor (New Phppowerpoint_ Style_color (' FFFFFFFF ')); $shape->createbreak (); $textRun = $shape->createtextrun ('-Representing a Presentation '), $textRun->getfont ()->setsize (), $textRun->getfont ()->setcolor (New Phppowerpoint_ Style_color (' FFFFFFFF ')); $shape->createbreak (); $textRun = $shape->createtextrun ('-Supports writing to Different file formats '), $textRun->getfont ()->setsize (), $textRun->getfont ()->setcolor (new Phppowerpoint_style_color (' FFFFFFFF '));//Create Templated Slideecho date (' H:i:s '). "Create Templated Slide\n "; $currentSlide = Createtemplatedslide ($objPHPPowerPoint); Local function//Create a shape (text) echo date (' H:i:s '). "Create a shape (rich text) \ n"; $shape = $currentSlide->createrichtextshape (); $shape->setheight (+); $shape- >setwidth (930), $shape->setoffsetx (Ten), $shape->setoffsety ($shape->getalignment (), Sethorizontal (phppowerpoint_style_alignment::horizontal_left); $textRun = $shape->createtextrun (' What\ ' s The Point? '); $textRun->getfont ()->setbold (true), $textRun->getfont ()->setsize (), $textRun->getfont () SetColor (New Phppowerpoint_style_color (' FFFFFFFF '));//Create a shape (text) echo date (' H:i:s '). "Create a shape (rich text) \ n"; $shape = $currentSlide->createrichtextshape (); $shape->setheight (+); $shape- >setwidth (930), $shape->setoffsetx, $shape->setoffsety, $shape->getalignment () Sethorizontal (phppowerpoint_style_alignment::horizontal_left); $textRun = $shape->createtextrun ('-Generate Slide DEcks '), $textRun->getfont ()->setsize (), $textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' FFFFFFFF ')); $shape->createbreak (); $textRun = $shape->createtextrun ('-represent business data '); $textRun->getfont ()- >setsize, $textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' FFFFFFFF ')); $shape Createbreak (); $textRun = $shape->createtextrun ('-Show a family slide show '); $textRun->getfont ()->setsize (28 ); $textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' FFFFFFFF ')); $shape->createbreak (); $ Textrun = $shape->createtextrun ('-... '), $textRun->getfont ()->setsize (), $textRun->getfont () SetColor (New Phppowerpoint_style_color (' FFFFFFFF ')); $shape->createbreak (); $textRun = $shape->createtextrun ( '-Export these to different formats '), $textRun->getfont ()->setsize (), $textRun->getfont ()->setcolor ( New Phppowerpoint_style_color (' FFFFFFFF ')); $shape->createbreak (); $Textrun = $shape->createtextrun ('-PowerPoint) ', $textRun->getfont ()->setsize ($textRun) GetFont ()->setcolor (New Phppowerpoint_style_color (' FFFFFFFF ')); $shape->createbreak (); $textRun = $shape Createtextrun ('-serialized '); $textRun->getfont ()->setsize (), $textRun->getfont ()->setcolor (new Phppowerpoint_style_color (' FFFFFFFF ')); $shape->createbreak (); $textRun = $shape->createtextrun ('-... (More to come), $textRun->getfont ()->setsize (), $textRun->getfont ()->setcolor (New Phppowerpoint_ Style_color (' FFFFFFFF '));//Create Templated Slideecho date (' H:i:s '). "Create templated slide\n"; $currentSlide = Createtemplatedslide ($objPHPPowerPoint); Local function//Create a shape (text) echo date (' H:i:s '). "Create a shape (rich text) \ n"; $shape = $currentSlide->createrichtextshape (); $shape->setheight (+); $shape- >setwidth (930), $shape->setoffsetx, $shape->setoffsety ($shape->getalignment ()-> Sethorizontal (phppowerpoint_style_alignment::horizontal_left); $textRun = $shape->createtextrun (' Need more info ?'); $textRun->getfont ()->setbold (true), $textRun->getfont ()->setsize (), $textRun->getfont () SetColor (New Phppowerpoint_style_color (' FFFFFFFF '));//Create a shape (text) echo date (' H:i:s '). "Create a shape (rich text) \ n"; $shape = $currentSlide->createrichtextshape (); $shape->setheight (+); $shape- >setwidth (930), $shape->setoffsetx, $shape->setoffsety, $shape->getalignment () Sethorizontal (phppowerpoint_style_alignment::horizontal_left); $textRun = $shape->createtextrun (' Check the Project site on CodePlex: '), $textRun->getfont ()->setsize (), $textRun->getfont ()->setcolor (new Phppowerpoint_style_color (' FFFFFFFF ')); $shape->createbreak (); $textRun = $shape->createtextrun ('); $textRun- >getfont (->setsize), $textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' FFFFFFFF '));// creatE Templated Slideecho Date (' H:i:s '). "Create templated slide\n"; *///test//data is transferred from the database for A For loop $row=array (' Titlepic ' =>array ('./images/love.gif '), '. Images/love1.gif ', './images/love2.gif ', './images/love3.gif '), ' Xsprice ' =>array ("", "", "" "," 333 "), ' cjid ' = >array (' + ', ' 222 ', ' 333 ', ' 3333 '), ' Lpid ' =>array (' 111 ', ' 222 ', ' 333 ', ' 444 '), ' Price ' =>array (' 111 ', ' 433 ', ' 243 ', ' 3245 ')), for ($i =0; $i <4; $i + +) {$currentSlide = CreateTemplatedSlide1 ($objPHPPowerPoint, $row ["Titlepic"] [$i ]); Local function//Create a shape (text)//echo date (' H:i:s '). "Create a shape (rich text) \ n"; $shape = $currentSlide->createrichtextshape (); $shape->setheight (+); $shape- >setwidth (930);//Adjust the height width of the font $shape->setoffsetx (); $shape->setoffsety;//$shape->getalignment ()- >sethorizontal (phppowerpoint_style_alignment::horizontal_left); $row ["Price"]=iconv ("Utf-8", "gb2312", $row [" Price "] [$i]); $textRun = $shape->createtextrun (' Gift net prices: '. $row [" Xsprice "] [$i]); $textRun->getfont () Setbold (TRUE);$textRun->getfont ()->setsize, $textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' # 000000 '); $shape = $currentSlide->createrichtextshape (); $shape->setheight (+); $shape->setwidth (930); $ Shape->setoffsetx, $shape->setoffsety, $shape->getalignment ()->sethorizontal (Phppowerpoint_ Style_alignment::horizontal_left);//Add multiline content starting from this $textrun = $shape->createtextrun (' Company number: ' $row ["Cjid"] [$i]); Textrun->getfont (->setsize), $textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' # 000000 '); $shape->createbreak (); $textRun = $shape->createtextrun (' Gift net number: ' $row ["lpid"] [$i]); $textRun GetFont (->setsize), $textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' #000000 '));//test/ /Save PowerPoint File}//echo date (' H:i:s '). "Write to PowerPoint2007 format\n"; $objWriter = Phppowerpoint_iofactory::createwriter ($objPHPPowerPoint, ' PowerPoint2007 '); $objWriter->save (Str_replace ('. php ', '.Pptx ', __file__)); header ("content-type:application/vnd.ms-powerpoint;"); Header ("location:02presentation.pptx");//Echo Memory peak Usage//echo date (' H:i:s '). "Peak Memory Usage:". (Memory_get_peak_usage (TRUE)/1024/1024). "mb\r\n";//Echo Done//echo date (' H:i:s '). "Done writing file.\r\n";/*** creates a templated slide** @param phppowerpoint $objPHPPowerPoint * @return phppowerpoint_s Lide*/function createTemplatedSlide1 (Phppowerpoint $objPHPPowerPoint, $cs 1) {//Create Slide$slide = $ Objphppowerpoint->createslide ();//ADD Background image$shape = $slide->createdrawingshape (), $shape SetName (' Background '); $shape->setdescription (' Background '); $shape->setpath ('./images/realdolmen_bg.jpg ') ; $shape->setwidth (950); $shape->setheight (720); $shape->setoffsetx (0); $shape->setoffsety (0);//ADD Logo$shape = $slide->createdrawingshape (), $shape->setname (' Phppowerpoint logo '); $shape->setdescription (' Phppowerpoint logo '), $shape->setpath ($cs 1); $shape->setheIght (+), $shape->setoffsetx (Ten), $shape->setoffsety;//Return Slidereturn $slide;} 

My problem is still in the study, if you have a better solution, please continue to post, look forward to more good share

I hope this article is helpful to you in PHP programming.

The above describes the PHP read ppt file method, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.