Create a PowerPoint Presentation Using C# and Embedding the Images
Today I will show how to Create PowerPoint Presentation
Using C# (Interop).
Creating PowerPoint Presentations Using Office Automation,
this will be very useful for IT departments and Organizations for their Employees.
We need to add following references
Embedding the Images in Microsoft PowerPoint Presentations.
using
Microsoft.Office.Interop.PowerPoint;
using
Microsoft.Office.Interop.Graph;
using
Microsoft.Office.Core;
Microsoft.Office.Interop.PowerPoint.Application
pptApplication = new
Microsoft.Office.Interop.PowerPoint.Application();
Microsoft.Office.Interop.PowerPoint.Slides
slides;
Microsoft.Office.Interop.PowerPoint._Slide
slide;
Microsoft.Office.Interop.PowerPoint.TextRange
objText;
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 = "journey to dotnet authority";
objText.Font.Name = "Trebuchet MS";
objText.Font.Size = 32;
string
innerChartFilePath = "D:\Images\Profile.png";
slide.Shapes.AddPicture(innerChartFilePath,
Microsoft.Office.Core.MsoTriState.msoFalse,
Microsoft.Office.Core.MsoTriState.msoTrue, 10, shape.Top, width,height);
pptPresentation.SaveAs(@"D:\Image"+DateTime.Now.Ticks.ToString()+".pptx",
Microsoft.Office.Interop.PowerPoint.PpSaveAsFileType.ppSaveAsDefault,
MsoTriState.msoTrue);
pptPresentation.Close();
pptApplication.Quit();
Thanks for share. I also recommend another way, more details is available here - Insert image to PPT in C#
ReplyDelete//create PPT document
Presentation presentation = new Presentation();
//insert image to PPT
string ImageFile2 = @" test.png";
RectangleF rect=new RectangleF(50, 100, 600, 245);
presentation.Slides[0].Shapes.AppendEmbedImage(ShapeType.Rectangle, ImageFile2, rect);
presentation.Slides[0].Shapes[0].Line.FillFormat.SolidFillColor.Color = Color.FloralWhite;
Well that looks complicated. I'm just started learning C# so it seems a bit hard for me to understand this. Can I use templates downloaded from http://www.poweredtemplate.com/ if I create presentation this way?
ReplyDelete