Creating PowerPoint presentations programmatically
Yes, you can.
You will want to look into MSDN which has a pretty good introduction to it.
I might give you a word of warning, Microsoft Office interop is compatible with an API which is now more than 10 years old. Because of this, it is downright nasty to use sometimes. If you have the money to invest in a good book or two, I think it would be money well spent.
Here's a starting point for you. Use the search feature on MSDN MSDN Webpage. It's good for any Microsoft C# .NET style stuff.
Specifically in regards to your question, this link should help: Automate PowerPoint from C#. EDIT LINK NOW DEAD :(. These two links are fairly close to the original KB article:
Automate Powerpoint from C# 1/2
Automate Powerpoint from C# 2/2
Finally, to whoever downvoted this: We were all learning one day, how to do something as a beginner is most definitely programming related, regardless of how new someone might be.
How to programmatically create a powerpoint from a list of images
It'll be something like this:
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();
Is there an API to make a MS Office 365 Powerpoint presentation programmatically?
There's a couple of ways to go about this. The first is to use MS' built in API that comes packaged with MS PPT, which is a set of COM objects. The second is to use the OpenXML standard which is a standard created after MS was forced to open up Office to the public. It allows you to create any MS Office document using an XML-based format.
Microsoft's PowerPoint API: These are tricky because of versioning and licensing. Just bear in mind that the COM API interacts (kind of) directly with the PowerPoint that is saved on your computer. So, if you move your application to a different computer, you'll have to make sure PPT is installed there and that the versioning and licensing are compatible with the COM objects you developed with (or, replace them with compatible COM objects). Start here if you want to go this route: https://learn.microsoft.com/en-us/visualstudio/vsto/powerpoint-solutions?view=vs-2017
OpenXML: The upside to using OpenXML is that it doesn't require PowerPoint to be installed on the computer your application is running on. Microsoft has a .net library that helps in creating OpenXML documents. Read this article on how to create a basic PPT presentation w/ their API: https://learn.microsoft.com/en-us/office/open-xml/how-to-create-a-presentation-document-by-providing-a-file-name . I also found this SO answer that has some good links in it: Sample create powerpoint with openxml
Good luck!
How can I programmatically create PowerPoint presentations. On Linux. For Free.
Open Office has an API. You can use the C++ bindings (doc available here). If you really need C
, you'll have to do some wrapping.. but hey, it's Christmas, isn't it ;-)
Open Office has export functions to create .ppt
compatible files.
Programmatically generated PowerPoint presentations break PowerPoint 2013
I've managed to find the solution.
Posting it here in case someone else ever runs into this issue.
I've used to OpenXml Sdk Validator on the generated presentation and that found the following error:
The element has unexpected child element 'http://schemas.openxmlformats.org/presentationml/2006/main:notesMasterIdLst'
This directed my attention to the Notes in the slides. Removing them fixed the issue and everything works fine.
Code for deleting the Notes (even if you don't see any notes when opening presentations in PP):
public static void RemoveNotesFromDoc(string docPath)
{
try
{
using (PresentationDocument pDoc =
PresentationDocument.Open(docPath, true))
{
foreach (var slide in pDoc.PresentationPart.SlideParts)
{
NotesSlidePart notes = slide.NotesSlidePart;
if (notes != null)
{
slide.DeletePart(slide.GetIdOfPart(slide.NotesSlidePart));
}
}
}
}
}
Create PowerPoint presention on the fly using C#
You can also refer to the following useful links:
Cloning Slides including Images and Charts in PowerPoint presentations & Using Open XML SDK 2.0 Productivity Tool
Add Chart on the fly to PowerPoint
Create PowerPoint .PPT programmatically using C#
How to create a PowerPoint presentation using C# and embed a Picture to the slide
Create Powerpoint with JavaScript
One JavaScript library that can generate Powerpoint binary files is PptxGenJS.
Genreally speaking, you can create a link with a data URL that has a Powerpoint MIME type:
data:ms-powerpoint;base64,aGVsbG8gd... // base64-encoded file
Run your logic to create a binary Powerpoint file, then base64-encode it (e.g. with btoa
), and then dynamically generate a link or redirect window.location
to the data URI.
var binaryPPFile = createPowerpointFromJSON(sourceJSON);
window.location = "data:ms-powerpoint;base64," + btoa(binaryPPFile);
My hypothetical createPowerpointFromJSON
function might make calls to the PptxGenJS API, or any other Powerpoint-generating API.
Programmatically create [Mail Merge] PowerPoint slides from Excel data
This is definately possible, and quite fun :-)
My first recommendation, is to create a powerpoint template using master views, with placeholders and titles all ready to go.
Then run the following powerpoint macro, so that you can get the name and index/id for every shape on the page.
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
This is a quick and dirty piece of code that puts the index & name of each item on your template page, into the shape itself. Memorise, record these. These are your reference points for where you want stuff to go.
I'm not going to go over the basics of looping etc, but go over the key code peices.
1) Open and gain control of powerpoint from excel.
Set ppt = CreateObject("PowerPoint.Application")
ppt.Visible = True
Set myPPT = ppt.Presentations.add
myPPT.ApplyTemplate ("Your template here.potx")
I then add all the pages I'll need, (this can vary depending on your application, and the number of rows, and whether you do this at the start, or in the process, will depend on whether you have mapped which page you should put the data onto, in your data)
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
I'm assuming that you know which page you want to update at each row, so:
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
Now, your application will definitely vary from this but I hope all of the basic necessities are there, and this should be a good starting point.
Related Topics
Memorycache Does Not Obey Memory Limits in Configuration
How Can One Generate and Save a File Client Side Using Blazor
ASP.NET Core Jwt Mapping Role Claims to Claimsidentity
Control Another Application Using C#
From Excel to Datatable in C# with Open Xml
Linq to SQL Where Clause Optional Criteria
Dependency Injection - New Instance Required in Several of a Classes Methods
Log4Net, How to Add a Custom Field to My Logging
How to Debug a Single Thread in Visual Studio
How to Ensure a Timestamp Is Always Unique
Return Content with Ihttpactionresult for Non-Ok Response
How to Convert a Class into Dictionary<String,String>
System.Badimageformatexception: Could Not Load File or Assembly
Can a Dbcontext Enforce a Filter Policy
Datetime.Parse("2012-09-30T23:00:00.0000000Z") Always Converts to Datetimekind.Local