简体   繁体   中英

Accessing powerpoint object programmatically using C#

I am accessing a ppt template in C# and creating a custom output programatically based on data.

Microsoft.Office.Interop.PowerPoint.Presentations objPresSet = null;
Microsoft.Office.Interop.Graph.Chart chart = null;
Microsoft.Office.Interop.Graph.DataSheet dataSheet = null;

objPres = objPresSet.Open(@"C:\Sample PPT application\WebSite4\WebSite4\2_Soundbite1.pptx", MsoTriState.msoFalse, MsoTriState.msoTrue, MsoTriState.msoTrue);
Microsoft.Office.Interop.PowerPoint._Slide objSlide = null;
objSlide = objPres.Slides[1];



foreach (Microsoft.Office.Interop.PowerPoint.Shape prefixShape in objSlide.Shapes)
{
    chart = (Microsoft.Office.Interop.Graph.Chart)prefixShape.OLEFormat.Object;
    dataSheet = chart.Application.DataSheet;
}

Now in case, when the template is of type '.ppt' then OLEFormat.Object as used above do exist, where as in case of '.pptx', it gives the following error

OLEFormat (unknown member) : Invalid request. This property only applies to OLE objects.

Not able to recognize it, I have searched msdn as well as other sites but no one is distinguishing '.ppt' and '.pptx'.

In the link Creating PowerPoint presentations programmatically , its mentioned that we can write a powerpoint programmatically, the problem I am facing is, I am able to do the same when the extension is '.ppt' whereas in case of '.pptx', I am unable to access charts and graphs being used in the template as the OLEFormat.Object that is used in accessing charts is not working in case of '.pptx', am I missing some dll for '.pptx' support, I am currently using 'Assembly Microsoft.Office.Interop.PowerPoint.dll, v2.0.50727'

objSlide[1].Shapes["myObjectNameInsideSlide1"].TextFrame.TextRange.Text = "Kiko";

上面的代码将访问幻灯片1中的文本框/形状

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM