我正在使用下面的代码加载一个pptx文件并保存到一个新的pptx中。我的代码很简单。但是在新的pptx文件中样式被破坏了。有人能帮上忙吗?
<?php
require_once 'vendor/autoload.php';
use PhpOffice\PhpPresentation\PhpPresentation;
use PhpOffice\PhpPresentation\IOFactory;
use PhpOffice\PhpPresentation\Style\Color;
use PhpOffice\PhpPresentation\Style\Alignment;
function createPPT($template){
$pptLayout = new \PhpOffice\PhpPresentation\DocumentLayout();
$pptLayout->setDocumentLayout($pptLayout::LAYOUT_SCREEN_16X10);
$pptTMPL = \PhpOffice\PhpPresentation\IOFactory::createReader('PowerPoint2007');
//$ppt = $pptTMPL->load("./ppt-template.pptx");
$ppt = $pptTMPL->load("./$template");
$ppt->setLayout($pptLayout);
$oWriterPPTX = IOFactory::createWriter($ppt, 'PowerPoint2007');
$oWriterPPTX->save(__DIR__ . "/sample2.pptx");
}
createPPT("a.pptx", "PowerPoint2007");发布于 2020-08-31 13:41:58
每当我们使用MS Office,从php导入/导出时,我们需要在相关代码中包括一个CSS文件。检查下面修改后的代码:
function createPPT($template)
{
$custom_css = "<your_url>/stye.css";
$pptLayout = new \PhpOffice\PhpPresentation\DocumentLayout();
$pptLayout->setDocumentLayout($pptLayout::LAYOUT_SCREEN_16X10);
$pptTMPL = \PhpOffice\PhpPresentation\IOFactory::createReader('PowerPoint2007');
//$ppt = $pptTMPL->load("./ppt-template.pptx");
$ppt = $pptTMPL->load("./$template" , $custom_css);
$ppt->setLayout($pptLayout);
$oWriterPPTX = IOFactory::createWriter($ppt, 'PowerPoint2007');
$oWriterPPTX->save(__DIR__ . "/sample2.pptx");
}尝尝这个。我希望这能支持你的项目。
https://stackoverflow.com/questions/63665188
复制相似问题