麻豆小视频在线观看_中文黄色一级片_久久久成人精品_成片免费观看视频大全_午夜精品久久久久久久99热浪潮_成人一区二区三区四区

首頁 > 開發 > PHP > 正文

PHP讀取PPT文件的方法

2024-05-04 23:40:53
字體:
來源:轉載
供稿:網友
這篇文章主要介紹了PHP讀取PPT文件的方法,通過php第三方類庫PHPPowerPoint實現對ppt文件的讀取操作,需要的朋友可以參考下
 

本文實例講述了PHP讀取PPT文件的方法。分享給大家供大家參考,具體如下:

最近做一個和FLASH有關的東西,其中就要用到在網站上看PPT就像百度,豆丁網那樣可以直接在網站上讀,在網上搜了半天沒搜到,都是些什么安裝個軟件什么的,PHP網站放到空間上,誰能讓你在哪裝軟件呢?不是在瞎扯么?不過還好,最后在國外一個網站上搜到了一個解決思路,就是一個PHP操作PPT的類,當然這個網站還提供了操作OFFICES軟件的其他類,不過是2007版的OFFICES,現把網址貼出來奉獻給大家:http://phppowerpoint.codeplex.com/。也可點擊此處本站下載。

這個類可以實現 PPT2007格式的讀寫/生成

下面也貼出當時看到的一個例子:

本例子使用phppowerpoint類,使用該類注意兩點,一個是了解參數含義,二注意字符集

<?phpheader("content-type:text/html;charset=utf-8");//字體設置防止亂碼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 = 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 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('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( '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('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->createBreak();$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();$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 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//從數據庫調取數據進行for循環$row=array('titlepic'=>array('./images/love.gif','./images/love1.gif','./images/love2.gif','./images/love3.gif'),'xsprice'=>array("55","33","22","333"),'cjid'=>array('100','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(100);$shape->setWidth(930);//調整字體的高度寬度$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('禮品網價格:'.$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 );//添加多行內容從這開始$textRun = $shape->createTextRun('公司編號:  '.$row["cjid"][$i]);$textRun->getFont()->setSize(36);$textRun->getFont()->setColor( new PHPPowerPoint_Style_Color( '#000000' ) );$shape->createBreak();$textRun = $shape->createTextRun('禮品網編號:  '.$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;}

我的問題仍然還在研究中,如果大家有更好的解決方法,請繼續貼,期待更多好的分享

希望本文所述對大家PHP程序設計有所幫助。



注:相關教程知識閱讀請移步到PHP教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 99精品视频在线免费观看 | 久久精品国产99国产精品亚洲 | 一边吃奶一边摸下娇喘 | 国内一区 | 一级黄色欧美 | 99视频有精品视频高清 | 久久精品国产一区二区 | 成人综合一区二区 | 久久欧美亚洲另类专区91大神 | 免费午夜视频在线观看 | 狠狠操天天射 | 久久久久久久久国产 | 在线a亚洲视频播放在线观看 | 欧美毛片免费观看 | 91嫩草丨国产丨精品入口 | 亚洲国产超高清a毛毛片 | 久草视频福利在线观看 | 国产成人高清成人av片在线看 | 黄色视屏免费在线观看 | 一级黄色免费大片 | 大号bbwassbigav头交 | 日日草夜夜操 | 国产羞羞视频在线观看 | 久久综合艹 | 91色一区二区三区 | 奶子吧naiziba.cc免费午夜片在线观看 | 免费日韩片 | av在线免费观看网址 | 久久av喷吹av高潮av懂色 | 另类亚洲孕妇分娩网址 | 成人在线视频免费看 | 欧美wwwsss9999| 精品久久久久久成人av | 欧美日本91精品久久久久 | 中文字幕在线免费观看电影 | 毛片大全在线观看 | 羞羞的视频免费在线观看 | 成人店女老板视频在线看 | 日韩蜜桃视频 | 国产二区三区视频 | 4p一女两男做爰在线观看 |