带有2张幻灯片的PHPPresentation文件需要修复

时间:2016-10-10 18:54:47

标签: repair 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);

1 个答案:

答案 0 :(得分:0)

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

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

然后将布局复制到每张新幻灯片:

$currentSlide->setSlideLayout($oSlideLayout);