Automation 以编程方式将多个演示文稿中的幻灯片合并到一个演示文稿中
我需要自动创建演示文稿(OpenOffice或Powerpoint)。演示文稿应将每个演示文稿的前两张幻灯片放在给定的目录中,然后将它们组合成一个演示文稿。我不知道应该采取什么方法来解决这个问题。任何指点都将不胜感激。谈到PowerPoint,您可以使用VBA宏来完成这项工作,例如Automation 以编程方式将多个演示文稿中的幻灯片合并到一个演示文稿中,automation,powerpoint,office-automation,openoffice-impress,Automation,Powerpoint,Office Automation,Openoffice Impress,我需要自动创建演示文稿(OpenOffice或Powerpoint)。演示文稿应将每个演示文稿的前两张幻灯片放在给定的目录中,然后将它们组合成一个演示文稿。我不知道应该采取什么方法来解决这个问题。任何指点都将不胜感激。谈到PowerPoint,您可以使用VBA宏来完成这项工作,例如 Sub Pull() Dim SrcDir As String, SrcFile As String SrcDir = PickDir() If SrcDir = "" Then Exit Sub
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
该代码不检查只读或密码保护的FIE,并将在它们上崩溃。还要注意不要在收集器文件本身上运行。否则它应该会起作用。我必须承认我很长时间没有检查代码了;-) 您可以通过谷歌搜索“powerpoint加入”来找到一个有用的工具来加入许多PPT。我很高兴能够为您提供所需的内容
另一种考虑方法,如果使用.NET,则在
< P>中讨论:一个简单快速的解决方案:I := Presentation.Slides.InsertFromFile(FileName,X,StartSlideNo,EndSlideNo);
Presentation.Slides.Item(I).ApplyTheme(FileName);
Presentation.Slides.Item(I).ApplyTemplate(FileName);
注:
X是在演示文稿中插入幻灯片的位置
我是幻灯片插入的实际位置
代码是用Delphi/Pascal编写的,但您可以轻松地进行转换…您可以使用.NET的Aspose.Slides来实现这一点。它甚至允许将OpenOffice和PowerPoint演示文稿连接在一起。视图
非常感谢。这正是我想要的。我只需要在Pull方法的循环中做一个小的更改:
importfromptpsrcdir+“\”+SrcFile,1,2
SrcFile=Dir
ahhh更正。。。我忘了更新线程。。。很抱歉正如您看到的,这里有一点抽象,如果下次需要拉幻灯片5-7,您可以重复使用相同的;-)你抓取幻灯片后不需要关闭源PPT文件吗?我决定改为使用。请参见,第一个答案显示了如何将演示文稿连接在一起。
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
I := Presentation.Slides.InsertFromFile(FileName,X,StartSlideNo,EndSlideNo);
Presentation.Slides.Item(I).ApplyTheme(FileName);
Presentation.Slides.Item(I).ApplyTemplate(FileName);
var presentation1 = new Presentation("presentation1.pptx");
var presentation2 = new Presentation("presentation2.odp");
var mergedPresentation = new Presentation();
while (mergedPresentation.Slides.Count > 0) mergedPresentation.Slides.RemoveAt(0);
// Adding two slides from the first PPTX presentation
mergedPresentation.Slides.AddClone(presentation1.Slides[0]);
mergedPresentation.Slides.AddClone(presentation1.Slides[1]);
// Adding two slides from the second OPD presentation
mergedPresentation.Slides.AddClone(presentation2.Slides[0]);
mergedPresentation.Slides.AddClone(presentation2.Slides[1]);
mergedPresentation.Save("mergedPresentation.pptx", SaveFormat.Pptx);