PHP method for reading pptfile _ php skills

Source: Internet
Author: User
This article mainly introduces how PHP reads pptfiles. it uses php third-party class library PHPPowerPoint to read pptfiles. For more information, see the following example. We will share this with you for your reference. The details are as follows:

Recently, I made a FLASH-related thing, which will be used to view PPT files on the website, just like Baidu, which can be read directly on the website by douding. I haven't searched the website for a long time, which of the following can install software and put PHP websites into space? Isn't it? But fortunately, I finally found a solution on a foreign website, that is, a PHP PPT class. of course, this website also provides other classes for operating the OFFICES software, but it is the OFFICES of Version 2007. now I will post the website to you at: http://phppowerpoint.codeplex.com /. You can also click here to download.

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

The following is an example:

In this example, the phppowerpoint class is used. pay attention to two points when using this class. one is to understand the parameter meaning, and the other is to pay attention to the character set.

<? Phpheader ("content-type: text/html; charset = utf-8"); // font setting prevents 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 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 = createTempla TedSlide ($ 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 ('inserduction '); $ 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 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 (100 ); $ shape-> setWidth (930); $ shape-> setOffsetX (10); $ shape-> setOffsetY (10); $ shape-> getAlignment ()-> setHorizontal (PHPPowerPoint_Style_Alignment:: HORIZ ONTAL_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 (new PHPPowerPoint_Style_Color ('ffff Ffff'); // 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 (100 ); $ shape-> setWidth (930); $ shape-> setOffsetX (10); $ shape-> setOffsetY (10); $ shape-> getAlignment ()-> setH Orizontal (PHPPowerPoint_Style_Alignment: HORIZONTAL_LEFT); $ textRun = $ shape-> createTextRun ('What \'s the 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-> createB Reak (); $ textRun = $ shape-> createTextRun ('-Export these 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 (); $ t ExtRun = $ 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 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 (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 slideecho date ('H: I: s '). "Create templated slide \ n"; * // test // retrieves data 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 ("55", "33", "22", "333 "), 'cjid' => array ('20140901', '20160901', '20160901', '20170901'), 'lpid '=> array ('20160901', '20160301 ', '20140901', '20140901'), 'price' => array ('20160901', '20160901', '20160301', '20160301 ')); 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); // adjust the font height and width $ shape-> 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 multi-row content starting from this $ 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 network No :'. $ 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 createTemplatedSlide1 (PHPPowerPoint $ objPHPPowerPoint, $ cs1) {// 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 ($ cs1); $ shape-> setHeight (120); $ shape-> setOffsetX (10 ); $ shape-> setOffsetY (10); // Return slidereturn $ slide ;}

My problem is still being studied. if you have a better solution, continue to post it and look forward to sharing more.

I hope this article will help you with PHP programming.

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.