【发布时间】:2014-06-05 08:39:37
【问题描述】:
我的要求是拆分 ppt/pptx 文件,然后合并特定的幻灯片。
我已经使用 PHP COM 成功地将 ppt/pptx 文件拆分为单独的幻灯片。现在我想使用一些 PHP 库来加入/合并幻灯片。
但是,除了 PHPPowerpoint 似乎没有。
我可以使用 PHPPowerpoint 创建幻灯片并使用它添加文本节点/图像,但它无法读取现有的 .ppt/pptx 文件并创建合并输出。
还有其他方法吗?我将不胜感激。
编辑: 我能够合并幻灯片,但不能正确合并。背景颜色/排序顺序仍然缺失。请帮忙,因为除了这个链接之外,网络上没有任何参考资料 -
http://msdn.microsoft.com/en-us/library/office/ff746640%28v=office.15%29.aspx
这里是代码 -
//SET Max exec time
ini_set("max_execution_time",-1);
$directory = 'c:/ppt/slides/';
$files_list = array_diff(scandir($directory,SCANDIR_SORT_DESCENDING), array('..', '.')); //Get list of all files from the sub slides folder
//var_dump($files_list); die;
$ppt_new = new COM("powerpoint.application") or die("Unable to instantiate Powerpoint 2");
$ppt_new->Presentations->Add(true); //Create the new(merged) ppt
$dirpath = "C:/ppt/slides/";
$ppt_new->Presentations[1]->Slides->Add( 1, 1 );
foreach($files_list as $file) { //Loop through all slides to merge those
$powerpnt = new COM("powerpoint.application") or die("Unable to instantiate Powerpoint");
echo "Adding slide...";
echo $file_path1 = realpath($dirpath.$file);
$pres = $powerpnt->Presentations->Open($file_path1, false, false, false) or die("Unable to open the slide");
echo $count = (int)$pres->Slides->Count."<--SLIDES COUNT<br>";
$i=1;
foreach($pres->Slides as $slide)
{
try {
$pptLayout = $slide->CustomLayout;
// var_dump($pptLayout); die;
// $ppt_new->Presentations[1]->Slides[$i]->FollowMasterBackground = false;
// $ppt_new->Presentations[1]->Slides[$i]->Background = $slide->Background;
//$ppt_new->Presentations[1]->Slides->Layout = $pptLayout;
$ppt_new->Presentations[1]->Slides->InsertFromFile($file_path1, $i, $i, $i);
// $ppt_new->Presentations[1]->SaveAs("merged11.ppt");
// $ppt_new->Export("created.ppt", "ppt");
$i++;
}
catch(Exception $e)
{
echo 'Caught exception: ', $e->getMessage(), "\n";
}
}
}
//Save the merged presentation
$powerpnt->quit();
$ppt_new->Presentations[1]->SaveAs("c:\ppt\merged121.ppt");
$ppt_new->Presentations[1]->Close();
$ppt_new->quit();
echo "Done!";
任何人都可以运行代码并找出为什么背景没有出现在合并的幻灯片中吗? 已经谢谢了。
【问题讨论】:
-
由于 PHPPowerPoint 不能用于你想要的;看起来你必须使用 COM(如果你在 Windows 服务器上),或者使用 PUNO 的 Open/Libre Office@
-
@MarkBaker 能否提供一个使用 COM 的示例?我找不到用于合并 ppts 的文件
-
我不使用 COM,所以我不能举个例子:作为 PHPOffice 库套件(包括 PHPPowerPoint)背后的开发团队之一,我相信使用我自己的代码,并且我以前不需要合并来自不同演示文稿的幻灯片
-
@MarkBaker 我在 COM 中添加了代码来合并幻灯片,但背景没有出现,幻灯片没有按顺序排序。可以看看吗?
-
如果在 PHP 中找不到可以帮助您完成的库,您可以在 Java 或 .NET 中使用 docx4j/pptx4j 企业版。
标签: php com merge powerpoint