php ppt read_PHP如何读取PPT?

匿名用户

1级

2013-10-13 回答

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 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('- 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 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 //从数据库调取数据进行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 slide return $slide; }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
操作PPT文档的PHP库,可以演示文档、添加幻灯片,支持图像、媒体的加入,作者的信息等等,并且完美兼容MS Office。本库配有十几个实际例子可以作为开发参考,而且配有对应的中文文档,使用起来相当方便,不需要在去啃英文单词。<?php date_default_timezone_set('UTC'); if (!defined('PHPPRESENTATION_TESTS_BASE_DIR')) {     define('PHPPRESENTATION_TESTS_BASE_DIR', realpath(__DIR__)); } $vendor = realpath(__DIR__ . '/../vendor'); if (file_exists($vendor . "/autoload.php")) {     require $vendor . "/autoload.php"; } else {     $vendor = realpath(__DIR__ . '/../../../');     if (file_exists($vendor . "/autoload.php")) {         require $vendor . "/autoload.php";     } else {         throw new Exception("Unable to load dependencies");     } } spl_autoload_register(function ($class) {     $class = ltrim($class, '\\');     $prefix = 'PhpOffice\\PhpPresentation\\Tests';     if (strpos($class, $prefix) === 0) {         $class = str_replace('\\', DIRECTORY_SEPARATOR, $class);         $class = join(DIRECTORY_SEPARATOR, array('PhpPresentation', 'Tests', '_includes')) .         substr($class, strlen($prefix));         $file = __DIR__ . DIRECTORY_SEPARATOR . $class . '.php';         if (file_exists($file)) {             require_once $file;         }     } }); require_once __DIR__ . "/../src/PhpPresentation/Autoloader.php"; \PhpOffice\PhpPresentation\Autoloader::register();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值