Powerpoint: Copying individual slides into new powerpoint files

匿名 (未验证) 提交于 2019-12-03 01:44:01

问题:

I want to save each slide in a powerpoint-file into seperate powerpoint-files, as well as store png images of each slide. In the end I want to create an archive of individual unique slides, so that all slides that are shown on some info screens are stored in this archive. This is what I have to far:

function exportSingleSlides(pathname, filename){     var app = new ActiveXObject("PowerPoint.Application");     app.Visible = true;      // Open the presentation     var presentation = app.Presentations.Open(pathname+filename, true);     var tmpPresentation; // Used to store a new presentation for each slide.      var e = new Enumerator(presentation.Slides);     var slide;     e.moveFirst();     var i = 0;     while (!e.atEnd()) {         i++;         slide = e.item(); // gets this slide          // Export slide to png         slide.Export(pathname + 'slide' + (i < 10 ? '0' + i : i) + '.png', 'PNG', 1920, 1080);          // Open new presentation         tmpPresentation = app.Presentations.Add();          // Copy current slide and paste into new presentation         slide.Copy();         tmpPresentation.Slides.Paste(1);          tmpPresentation.SaveAs(pathname + 'slide' + (i < 10 ? '0' + i : i));         tmpPresentation.Close();         e.moveNext();     }      // Close the presentation. (But how do I close powerpoint entirely?)     presentation.Close();     app.Quit(); }  // Which file are we looking at? var pathname = 'C:\\Users\\Stian\\Dropbox\\jobb\\RB\\powerpoint parser\\'; var filename = 'test.pptx';  exportSingleSlides(pathname, filename);

This saves the slides to png as I want, and it also saves each slide as it's own powerpoint-file. But it's not copying it as it should. I think it might be missing the template, because headers and footers aren't included in the new copy. I'm using the powerpoint developer reference pages, but I can't seem to find a good way to copy/duplicate a slide as-is. Any suggestions?

回答1:

I've figured it out. Doing as below instead of just copying will do the trick.

// Get the layout from the source slide layout = slide.CustomLayout;  // Copy current slide and paste into new presentation slide.Copy(); tmpPresentation.Slides.Paste(1);  // Set the layout tmpPresentation.Slides(1).CustomLayout = layout;

Now I'm getting an unspecified error when trying to save the new file, but that's a whole other problem.



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!