c# – 如何以编程方式从图像列表中创建powerpoint

我见过这个问题: Creating PowerPoint presentations programmatically,但那个问题问“你能吗?”答案是肯定的.

但我问“怎么样?”特别是“从图像列表?”

这就是我打破ppt到图像的方法

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

我该如何反过来?

解决方法

它会是这样的:
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();

相关文章

在项目中使用SharpZipLib压缩文件夹的时候,遇到如果目录较深,则压缩包中的文件夹同样比较深的问题。比...
项目需要,几十万张照片需要计算出每个照片的特征值(调用C++编写的DLL)。 业务流程:选择照片...
var array = new byte[4]; var i = Encoding.UTF8.GetBytes(100.ToString("x2"));//...
其实很简单,因为Combox的Item是一个K/V的object,那么就可以把它的items转换成IEnumerable<Dic...
把.net4.6安装包打包进安装程序。 关键脚本如下: 头部引用字符串对比库 !include "WordFunc....
项目需求(Winform)可以批量打印某个模板,经过百度和摸索,使用iTextSharp+ZXing.NetʿreeSp...