以编程方式从Excel数据创build PowerPoint幻灯片

使用Powerpoint 2010 for Mac。

我有一个100幻灯片演示文稿,需要每周创build。 每张幻灯片都有相同的模板。 每张幻灯片上的元素由5个文本字段和一张图片组成,每张幻灯片对应于Excel表格中的数据列。

任何人都可以指向我的一个代码示例或详细的演练如何可以遍历这个Excel文件的行,并以编程方式创build这些幻灯片?

这绝对是可能的,而且很有趣:-)

我的第一个build议是使用主视图创build一个幻灯片模板,占位符和标题都准备好了。 然后运行下面的PowerPointmacros,这样你就可以得到页面上每个形状的名称和索引/ ID。

Sub nameshapes() Dim sld As Slide Dim shp As Shape Set sld = Application.ActivePresentation.Slides(1) For Each shp In sld.Shapes shp.TextEffect.Text = shp.name & " " & shp.ID Next End Sub 

这是一个快速和肮脏的代码,将每个项目的索引和名称放在您的模板页面,形状本身。 记住,logging这些。 这些是你想要去的地方的参考点。 我不打算循环等的基本知识,但去了关键的代码peices。

1)从Excel中打开并获得对powerpoint的控制。

 Set ppt = CreateObject("PowerPoint.Application") ppt.Visible = True Set myPPT = ppt.Presentations.add myPPT.ApplyTemplate ("Your template here.potx") 

然后,我添加所有需要的页面(这可以根据您的应用程序和行数而变化,而且您是在开始时还是在此过程中执行此操作将取决于您是否映射了哪个页面应该把数据放到你的数据里)

 For x = 1 To NumberOfPages myPPT.Slides.AddSlide x, myPPT.SlideMaster.CustomLayouts(2) '2 is the index of the template I wish to use (in master views, the index is the order they're in (starting from 1) Next 

我假设你知道哪一页你想在每一行更新,所以:

 For Each dr In .rows 'I'm storing my data in a special collection, you will need to adapt this Set currSlide = myPPT.Slides(dr.cell("OutputPage").Value) 'go to the right page Sheets(dr.cell("SheetName").toString).Activate 'make sure the data you want is active ActiveSheet.Range(Names(dr.cell("ChartID").Value)).CopyPicture 'copy the table as a picture, this is easiest for formatting in powerpoint, but you can do lots of things here currSlide.Select currSlide.Shapes("Content Placeholder " & dr.cell("Output Position").toString).Select 'the output position is the index from the first bit of code, ppt.ActiveWindow.View.Paste next 

现在,你们的申请肯定会有所不同,但是我希望所有的基本必需品都在那里,这应该是一个很好的起点。

独立应用程序SlideMight接受PowerPoint模板,JSON数据文件和configuration,并将其合并到演示文稿中。

迭代可能超过幻灯片和表格行,它们可能是嵌套的。 支持图像replace,也在表格单元格中。

免责声明 :我是SlideMight的开发者和销售商。