如何以编程方式从图像列表创建PowerPoint [英] How to programmatically create a powerpoint from a list of images

查看:83
本文介绍了如何以编程方式从图像列表创建PowerPoint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了以下问题:以编程方式创建PowerPoint演示文稿,但是该问题询问你能?"答案是是".

I've seen this question: Creating PowerPoint presentations programmatically, but that question asks "Can you?" to which the answer is "yes".

但是我在问如何?"特别是来自图像列表?"

But I'm asking "How?" and specifically "From a list of images?"

这是我将ppt分解为图像的方法

Here's what I do to break a ppt up into images

var app = new PowerPoint.Application();
var pres = app.Presentations;
var file = pres.Open(input, MsoTriState.msoFalse, MsoTriState.msoFalse, MsoTriState.msoFalse);
file.SaveAs(output, Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsJPG, MsoTriState.msoTrue);
file.Close();
app.Quit();

我该如何做相反的事情?

How do I do the reverse?

推荐答案

它将是这样的:

string pictureFileName = "C:\\temp\\test.jpg"; 

Application pptApplication = new Application();

Microsoft.Office.Interop.PowerPoint.Slides slides;
Microsoft.Office.Interop.PowerPoint._Slide slide;
Microsoft.Office.Interop.PowerPoint.TextRange objText;

// Create the Presentation File
Presentation pptPresentation = pptApplication.Presentations.Add(MsoTriState.msoTrue);

Microsoft.Office.Interop.PowerPoint.CustomLayout customLayout = pptPresentation.SlideMaster.CustomLayouts[Microsoft.Office.Interop.PowerPoint.PpSlideLayout.ppLayoutText];

// Create new Slide
slides = pptPresentation.Slides;
slide = slides.AddSlide(1, customLayout);

// Add title
objText = slide.Shapes[1].TextFrame.TextRange;
objText.Text = "test";
objText.Font.Name = "Arial";
objText.Font.Size = 32;

objText = slide.Shapes[2].TextFrame.TextRange;
objText.Text = "Content goes here\nYou can add text\nItem 3";

Microsoft.Office.Interop.PowerPoint.Shape shape = slide.Shapes[2];
slide.Shapes.AddPicture(pictureFileName,Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoTrue,shape.Left, shape.Top, shape.Width, shape.Height);

slide.NotesPage.Shapes[2].TextFrame.TextRange.Text = "Test";

pptPresentation.SaveAs(@"c:\temp\test.pptx", Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault, MsoTriState.msoTrue);
//pptPresentation.Close();
//pptApplication.Quit();

这篇关于如何以编程方式从图像列表创建PowerPoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆