I'm trying to automate a process using PowerPoint from C#, to do this I want to open (or create a new) PowerPoint presentation, add a slide, and save the document.
I've got the entire office 2019 package installed on my machine and can access the ppt api by referencing the Interop.Microsoft.Office.Interop.PowerPoint (from the Microsoft PowerPoint 16.0 Object Library reference) along with Interop.Microsoft.Office.Core (from the Microsoft Office 16.0 Object Library reference).
I try to open a powerpoint using the following code:
using Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Core;
class PowerPointManager
{
public PowerPointManager()
{
string powerPointFileName = @"C:\temp\test.pptx";
Application pptApplication = new Application();
Presentation ppt = pptApplication.Presentations.Open(powerPointFileName, MsoTriState.msoTrue); //MsoTriState comes from Microsoft.Office.Core
}
}
However this results in an error on the line pptApplication.Presentations.Open)
Error CS0012 The type 'MsoTriState' is defined in an assembly that is not referenced. You must add a reference to assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'
Even though MsoTriState is most definitely defined in Microsoft.Office.Core which is part of the office.dll assembly (msdn reference)
When I try to use VS2019's quick actions I get the option to "Add reference to "office Version 15.0.0.0"". Performing this quick actions opens up the Reference Manager, but does not add any references. Manually searching for "Office" doesn't yield any result simply named "office" either. The closest being "Microsoft Office 16.0 Object Library", which is already referenced.
As far as I can tell this is the same MsoTriStrate the function parameter is asking for, so why is it not accepting this? Trying to substitute the MsoTriState value for its integer value (e.g. -1 for true) doesn't work either.
Using .NET Core 3.1 WinForms, with Office 2019 (incl. powerpoint) 32bit, on W10 x64 enterprise and Visual Studio 2019 with the Office/Sharepoint development toolset installed.