以编程方式将多个演示文稿中的幻灯片组合到一个演示

时间:2011-03-15 18:44:45

标签: automation powerpoint office-automation openoffice-impress

我需要自动创建演示文稿(OpenOffice或Powerpoint)。演示文稿应该将给定目录中每个演示文稿的前两张幻灯片放在一起,然后将它们组合成一个演示文稿。我很困惑我应该采取什么方法来解决这个问题。任何指针都将受到赞赏。

5 个答案:

答案 0 :(得分:12)

谈到PowerPoint,您可以使用VBA宏来完成这项工作,例如

Sub Pull()
Dim SrcDir As String, SrcFile As String

    SrcDir = PickDir()
    If SrcDir = "" Then Exit Sub

    SrcFile = Dir(SrcDir & "\*.ppt")

    Do While SrcFile <> ""
        ImportFromPPT SrcDir + "\" + SrcFile, 1, 2
        SrcFile = Dir()
    Loop

End Sub

选择源目录,您可以使用此功能

Private Function PickDir() As String
Dim FD As FileDialog

    PickDir = ""

    Set FD = Application.FileDialog(msoFileDialogFolderPicker)
    With FD
        .Title = "Pick a directory to work on"
        .AllowMultiSelect = False
        .Show
        If .SelectedItems.Count <> 0 Then
            PickDir = .SelectedItems(1)
        End If
    End With

End Function

现在 - 重点是从保留源格式插入另一个PPT的幻灯片。这是一个棘手的事情,因为PPT VBA InsertFromFile方法没有用处。微软给了我们很多时间在无数20小时的调试会话中找出困难的方法:-)而且你需要输入大量的代码来正确完成它 - 比手动使用对话要复杂得多,特别是如果你的源幻灯片偏离源主幻灯片。

如果你的PPT坚持他们的主人,你可以安全地省略“&gt;&gt;&gt;&gt;”

之间的所有代码
Private Sub ImportFromPPT(FileName As String, SlideFrom As Long, SlideTo As Long)
Dim SrcPPT As Presentation, SrcSld As Slide, Idx As Long, SldCnt As Long

    Set SrcPPT = Presentations.Open(FileName, , , msoFalse)
    SldCnt = SrcPPT.Slides.Count

    If SlideFrom > SldCnt Then Exit Sub
    If SlideTo > SldCnt Then SlideTo = SldCnt

    For Idx = SlideFrom To SlideTo Step 1
        Set SrcSld = SrcPPT.Slides(Idx)
        SrcSld.Copy
        With ActivePresentation.Slides.Paste
            .Design = SrcSld.Design
            .ColorScheme = SrcSld.ColorScheme
            ' if slide is not following its master (design, color scheme)
            ' we must collect all bits & pieces from the slide itself

            ' >>>>>>>>>>>>>>>>>>>>

            If SrcSld.FollowMasterBackground = False Then
                .FollowMasterBackground = False
                .Background.Fill.Visible = SrcSld.Background.Fill.Visible
                .Background.Fill.ForeColor = SrcSld.Background.Fill.ForeColor
                .Background.Fill.BackColor = SrcSld.Background.Fill.BackColor

                ' inspect the FillType object
                Select Case SrcSld.Background.Fill.Type
                    Case Is = msoFillTextured
                        Select Case SrcSld.Background.Fill.TextureType
                        Case Is = msoTexturePreset
                            .Background.Fill.PresetTextured (SrcSld.Background.Fill.PresetTexture)
                        Case Is = msoTextureUserDefined
                        ' TextureName gives a filename w/o path
                        ' not implemented, see picture handling
                        End Select

                    Case Is = msoFillSolid
                        .Background.Fill.Transparency = 0#
                        .Background.Fill.Solid

                    Case Is = msoFillPicture
                        ' picture cannot be copied directly, need to export and re-import slide image
                        If SrcSld.Shapes.Count > 0 Then SrcSld.Shapes.Range.Visible = False
                        bMasterShapes = SrcSld.DisplayMasterShapes
                        SrcSld.DisplayMasterShapes = False
                        SrcSld.Export SrcPPT.Path & SrcSld.SlideID & ".png", "PNG"

                        .Background.Fill.UserPicture SrcPPT.Path & SrcSld.SlideID & ".png"
                        Kill (SrcPPT.Path & SrcSld.SlideID & ".png")

                        SrcSld.DisplayMasterShapes = bMasterShapes
                        If SrcSld.Shapes.Count > 0 Then SrcSld.Shapes.Range.Visible = True

                    Case Is = msoFillPatterned
                        .Background.Fill.Patterned (SrcSld.Background.Fill.Pattern)

                    Case Is = msoFillGradient

                        ' inspect gradient type
                        Select Case SrcSld.Background.Fill.GradientColorType
                        Case Is = msoGradientTwoColors
                            .Background.Fill.TwoColorGradient
                                SrcSld.Background.Fill.GradientStyle , _
                                SrcSld.Background.Fill.GradientVariant
                        Case Is = msoGradientPresetColors
                            .Background.Fill.PresetGradient _
                                SrcSld.Background.Fill.GradientStyle, _
                                SrcSld.Background.Fill.GradientVariant, _
                                SrcSld.Background.Fill.PresetGradientType
                        Case Is = msoGradientOneColor
                            .Background.Fill.OneColorGradient _
                                SrcSld.Background.Fill.GradientStyle, _
                                SrcSld.Background.Fill.GradientVariant, _
                                SrcSld.Background.Fill.GradientDegree
                        End Select

                    Case Is = msoFillBackground
                        ' Only shapes - we shouldn't come here
                End Select
            End If

            ' >>>>>>>>>>>>>>>>>>>>

        End With
    Next Idx

End Sub

代码不检查只读或密码保护的fies并且会崩溃。另外要注意不要遍历收集器文件本身。否则它应该工作。我必须承认我很长时间没有审查过代码; - )

答案 1 :(得分:0)

您可以谷歌“powerpoint join”找到一个有用的工具来加入许多ppts。

答案 2 :(得分:0)

我很高兴@miked能够得到你所需要的东西。

如果使用.NET,另一种需要考虑的方法在this post

中讨论

答案 3 :(得分:0)

一个简单而快速的解决方案:

I := Presentation.Slides.InsertFromFile(FileName,X,StartSlideNo,EndSlideNo);
Presentation.Slides.Item(I).ApplyTheme(FileName);
Presentation.Slides.Item(I).ApplyTemplate(FileName);

注意: X是在演示文稿中插入幻灯片的地方

我是插入幻灯片的实际位置

代码是用Delphi / Pascal编写的,但是您可以轻松地对其进行转换...

答案 4 :(得分:0)

您可以使用Aspose.Slides for .NET进行此操作。它甚至允许将OpenOffice和PowerPoint演示文稿一起加入。查看this article

someService
    .UpdateAsync(Arg.Do<Action<OneClass, TwoClass>>(x => x(data)))
    .Returns(Task.CompletedTask);