Powerpoint:将单个幻灯片复制到新的powerpoint文件中

时间:2014-03-27 12:43:41

标签: javascript powerpoint

我想将powerpoint文件中的每张幻灯片保存到单独的powerpoint文件中,以及存储每张幻灯片的png图像。最后,我想创建一个单独的幻灯片存档,以便在某些信息屏幕上显示的所有幻灯片都存储在此存档中。这就是我所要做的:

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);

这会根据需要将幻灯片保存到png,并且还会将每张幻灯片保存为自己的powerpoint文件。但它并没有像它应该的那样复制它。我认为它可能缺少模板,因为页眉和页脚不包含在新副本中。我使用的是powerpoint developer reference pages,但我似乎找不到按原样复制/复制幻灯片的好方法。有什么建议吗?

1 个答案:

答案 0 :(得分:0)

我已经弄明白了。如下所示,而不仅仅是复制将起到作用。

// 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;

现在我在尝试保存新文件时收到了一个未指定的错误,但这是另一个问题。