我的要求是拆分ppt/pptx文件,然后合并特定的幻灯片。使用COM和PHP合并/创建PowerPoint幻灯片幻灯片
我已经使用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](http://www.wstech2.net/index.php?do=0a,01 ,05) –
@MarkBaker您可以使用COM提供示例吗?我无法找到合并ppts的人 –
我不使用COM,因此我不能举一个例子:作为PHPOffice套件库(包括PHPPowerPoint)背后的开发团队之一,我相信使用我自己的代码,我还没有任何需要合并幻灯片从 –