包含 2 张幻灯片的 PHPPresentation 文件需要修复

PHPPresentation file with 2 slides requires repair

我正在编写一个脚本来创建包含多张幻灯片的演示文稿。当我添加第一张幻灯片时,脚本工作正常。

$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);

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

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

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

$currentSlide->setSlideLayout($oSlideLayout);