2016-10-10 60 views
0

我正在制作一个脚本以创建带有多张幻灯片的演示文稿。当我添加第一张幻灯片时,脚本工作正常。带2张幻灯片的PHPPresentation文件需要修复

$colorBlack = new Color('FF000000'); 


$objPHPPresentation = new PhpPresentation(); 

$objPHPPresentation->getDocumentProperties()->setCreator('PHPOffice') 
    ->setLastModifiedBy('PHPPresentation Team') 
    ->setTitle('Sample 01 Title') 
    ->setSubject('Sample 01 Subject') 
    ->setDescription('Sample 01 Description') 
    ->setKeywords('office 2007 openxml libreoffice odt php') 
    ->setCategory('Sample Category'); 

$objPHPPresentation->removeSlideByIndex(0); 

$currentSlide = createTemplatedSlide($objPHPPresentation); 

$shape = $currentSlide->createRichTextShape(); $shape->setHeight(200);  
$shape->setWidth(600); $shape->setOffsetX(10); $shape->setOffsetY(400); 
$shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT); 

$textRun = $shape->createTextRun('slide 1 text 1'); 
$textRun->getFont()->setBold(true); 
$textRun->getFont()->setSize(28); 
$textRun->getFont()->setColor($colorBlack); $shape->createBreak(); 

$textRun = $shape->createTextRun('slide 1 text 2'); 
$textRun->getFont()->setBold(true); 
$textRun->getFont()->setSize(60); 
$textRun->getFont()->setColor($colorBlack); 

所以上面的代码工作正常。然后,当我为第二张幻灯片添加代码时,使用PowerPoint打开时出现错误,指出内容有问题并且需要修复文件。

这是我为第二张幻灯片添加的代码。它基本上是上一张幻灯片的副本。

$currentSlide = createTemplatedSlide($objPHPPresentation); 

$shape = $currentSlide->createRichTextShape(); 
$shape->setHeight(200); 
$shape->setWidth(600); 
$shape->setOffsetX(10); 
$shape->setOffsetY(400); 
$shape->getActiveParagraph()->getAlignment()->setHorizontal(Alignment::HORIZONTAL_LEFT); 

$textRun = $shape->createTextRun('second slide text 1'); 
$textRun->getFont()->setBold(true); 
$textRun->getFont()->setSize(28); 
$textRun->getFont()->setColor($colorBlack); $shape->createBreak(); 

$textRun = $shape->createTextRun('second slide text 2'); 
$textRun->getFont()->setBold(true); 
$textRun->getFont()->setSize(60); 
$textRun->getFont()->setColor($colorBlack); 

回答

0

我在另一个论坛上得到了这个。复制布局。

$objPHPPresentation = new PhpPresentation(); 
$oMasterSlide = $objPHPPresentation->getAllMasterSlides()[0]; 
$oSlideLayout = $oMasterSlide->getAllSlideLayouts()[0]; 

然后布局复制到每个新的幻灯片:

$currentSlide->setSlideLayout($oSlideLayout); 
+0

你好,我想这样做,但我没有可用的'getAllMasterSlides'方法。您使用的是哪个版本的PhpPresentation? –