我的要求是拆分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!";任何人都可以运行代码,找到为什么背景不会出现在合并的幻灯片中? 谢谢。
My requirement is to split ppt/pptx files and then merge particular slides.
I have successfully split ppt/pptx files into seperate slides using PHP COM. Now I want to join/merge the slides using some PHP Library.
However, there doesn't seem to be one except PHPPowerpoint.
I can use PHPPowerpoint to create slides and add text nodes/images using it but it cannot read existing .ppt/pptx files and create a merged output.
Is there another way? I will appreciate any help at all.
EDIT: I was able to merge slides but not Properly.. the background color/sort order is still missing. Please help as there are no references on the web on this except for this link -
http://msdn.microsoft.com/en-us/library/office/ff746640%28v=office.15%29.aspx
Here is the code -
//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!";Can anyone please run the code and find why the background is not coming in the merged slide? Thanks already.
最满意答案
解决了:
我按照此链接http://skp.mvps.org/pptxp001.htm并手动将VBA中的示例代码转换为PHP。 基本上InsertFromFile()方法不能正常工作,所以我根据MSDN使用了Copy()和Paste()方法( http://msdn.microsoft.com/en-us/library/office/ff746640%28v=office。 15%29.aspx )
SOLVED:
I followed this link http://skp.mvps.org/pptxp001.htm and manually converted the example code in VBA into PHP. Basically the InsertFromFile() method was not working properly so I used Copy() and Paste() methods as per the MSDN (http://msdn.microsoft.com/en-us/library/office/ff746640%28v=office.15%29.aspx)
更多推荐
发布评论