加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 08:20:00 所属栏目:百科 来源:网络整理
导读:我见过这个问题: Creating PowerPoint presentations programmatically,但那个问题问“你能吗?”答案是肯定的. 但我问“怎么样?”特别是“从图像列表?” 这就是我打破ppt到图像的方法 var app = new PowerPoint.Application();var pres = app.Presentati
我见过这个问题: 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:temptest.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 herenYou can add textnItem 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:temptest.pptx",Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault,MsoTriState.msoTrue);
//pptPresentation.Close();
//pptApplication.Quit();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读