How to read ppt files in PHP _php tips

Source: Internet
Author: User
Tags echo date memory usage

This article illustrates the way PHP reads a ppt file. Share to everyone for your reference, specific as follows:

Recently made a flash-related thing, which will be used on the site to see ppt like Baidu, beans, such as can be directly in the Web site read, search on the internet for a long time did not search, are what to install a software or anything, PHP site to space, who can let you install the software? Isn't that a nonsense? But fortunately, finally in a foreign site to find 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 posted on the Web site dedicated to everyone: http:// phppowerpoint.codeplex.com/. Can also click here to download the site.

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

Here's an example of what we 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 attention character set

<?php header ("Content-type:text/html;charset=utf-8");//font settings to 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 2007 PPTX Test Document");
$objPHPPowerPoint->getproperties ()->setsubject ("Office 2007 PPTX Test Document"); $objPHPPowerPoint->getproperties ()->setdescription ("Test document for Office 2007 PPTX, generated using PHP
Classes. ");
$objPHPPowerPoint->getproperties ()->setkeywords ("Office 2007 OPENXML PHP"); $objPHPPowerPoint->GetProperties ()->setcategory ("Test result file"); Remove the slide//echo date (' H:i:s ').
"Remove the 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 (200);
$shape->setwidth (600);
$shape->setoffsetx (10);
$shape->setoffsety (400);
$shape->getalignment ()->sethorizontal (phppowerpoint_style_alignment::horizontal_left);
$textRun = $shape->createtextrun (' Introduction to ');
$textRun->getfont ()->setbold (true);
$textRun->getfont ()->setsize (28);
$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 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 (100);
$shape->setwidth (930);
$shape->setoffsetx (10);
$shape->setoffsety (10);
$shape->getalignment ()->sethorizontal (phppowerpoint_style_alignment::horizontal_left);
$textRun = $shape->createtextrun (' What is Phppowerpoint? ');
$textRun->getfont ()->setbold (true);
$textRun->getfont ()->setsize (48);
$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 (600); $shape,; SetWidth (930);
$shape->setoffsetx (10);
$shape->setoffsety (100);
$shape->getalignment ()->sethorizontal (phppowerpoint_style_alignment::horizontal_left);
$textRun = $shape->createtextrun ('-A class library ');
$textRun->getfont ()->setsize (36);
$textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' ffffffff '));
$shape->createbreak ();
$textRun = $shape->createtextrun ('-written in PHP ');
$textRun->getfont ()->setsize (36);
$textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' ffffffff '));
$shape->createbreak ();
$textRun = $shape->createtextrun ('-representing a presentation ');
$textRun->getfont ()->setsize (36);
$textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' ffffffff '));
$shape->createbreak ();
$textRun = $shape->createtextrun ('-Supports writing to different file formats ');
$textRun->getfont ()->setsize (36); $textRun->getfont ()->setcolor (The New Phppowerpoint_style_color (' FFFFFFFF ')); 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 (100);
$shape->setwidth (930);
$shape->setoffsetx (10);
$shape->setoffsety (10);
$shape->getalignment ()->sethorizontal (phppowerpoint_style_alignment::horizontal_left);
$textRun = $shape->createtextrun (' what\ ' s point?);
$textRun->getfont ()->setbold (true);
$textRun->getfont ()->setsize (48);
$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 (600);
$shape->setwidth (930);
$shape->setoffsetx (10);
$shape->setoffsety (100); $shape->getalignment ()->sethorizontal (PHppowerpoint_style_alignment::horizontal_left);
$textRun = $shape->createtextrun ('-Generate slide decks ');
$textRun->getfont ()->setsize (36);
$textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' ffffffff '));
$shape->createbreak ();
$textRun = $shape->createtextrun ('-represent business data ');
$textRun->getfont ()->setsize (28);
$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 (28);
$textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' ffffffff '));
$shape->createbreak ();
$textRun = $shape->createtextrun ('-Export to different formats '); $textRun->getfont ()->SetSize (36);
$textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' ffffffff '));
$shape->createbreak ();
$textRun = $shape->createtextrun ('-PowerPoint 2007 ');
$textRun->getfont ()->setsize (28);
$textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' ffffffff '));
$shape->createbreak ();
$textRun = $shape->createtextrun ('-serialized ');
$textRun->getfont ()->setsize (28);
$textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' ffffffff '));
$shape->createbreak (); $textRun = $shape->createtextrun ('-...
(more to come) ... ');
$textRun->getfont ()->setsize (28);
$textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' ffffffff ')); 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 (100);
$shape->setwidth (930);
$shape->setoffsetx (10);
$shape->setoffsety (10);
$shape->getalignment ()->sethorizontal (phppowerpoint_style_alignment::horizontal_left);
$textRun = $shape->createtextrun (' Need more info? ');
$textRun->getfont ()->setbold (true);
$textRun->getfont ()->setsize (48);
$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 (600);
$shape->setwidth (930);
$shape->setoffsetx (10);
$shape->setoffsety (100);
$shape->getalignment ()->sethorizontal (phppowerpoint_style_alignment::horizontal_left);
$textRun = $shape->createtextrun (' Check the project site on CodePlex: ');
$textRun->getfont ()->setsize (36);
$textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' ffffffff '));
$shape->createbreak (); $textRun= $shape->createtextrun (');
$textRun->getfont ()->setsize (36);
$textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' ffffffff ')); Create Templated slide echo Date (' H:i:s '). "Create templated slide\n"; * *//test//From database fetch data for loop $row =array (' Titlepic ' =>array ('./images/love.gif ', './ Images/love1.gif ', './images/love2.gif ', './images/love3.gif '), ' Xsprice ' =>array ("The", "the", "" "," 333 "), ' cjid ' = >array (' m ', ' 222 ', ' 333 ', ' 3333 '), ' Lpid ' =>array (' A ', ' 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 (100);
$shape->setwidth (930);
Adjusts the height width of the font $shape-&GT;SETOFFSETX (20);
$shape->setoffsety (400); $shape->getalignment ()->sethorizontal (phppowerpoint_style_alignment::Horizontal_left);
$row ["Price"]=iconv ("Utf-8", "gb2312", $row ["Price"] [$i]);
$textRun = $shape->createtextrun (' Gift net Price: '. $row ["Xsprice"] [$i]);
$textRun->getfont ()->setbold (true);
$textRun->getfont ()->setsize (48);
$textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' #000000 '));
$shape = $currentSlide->createrichtextshape ();
$shape->setheight (600);
$shape->setwidth (930);
$shape->setoffsetx (20);
$shape->setoffsety (500);
$shape->getalignment ()->sethorizontal (phppowerpoint_style_alignment::horizontal_left);
Add multiline content from here $textRun = $shape->createtextrun (' Company No.: '. $row ["Cjid"] [$i]);
$textRun->getfont ()->setsize (36);
$textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' #000000 '));
$shape->createbreak ();
$textRun = $shape->createtextrun (' Gift net number: '. $row ["Lpid"] [$i]);
$textRun->getfont ()->setsize (36);
$textRun->getfont ()->setcolor (New Phppowerpoint_style_color (' #000000 ')); Test//Save PowerpoiNT 2007 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_slide/function creat
ETemplatedSlide1 (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 (120);
$shape->setoffsetx (10);
$shape->setoffsety (10);
Return to slide return $slide;

 }

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

I hope this article will help you with the PHP program design.

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.