简体   繁体   English

使用C#以编程方式访问Powerpoint对象

[英]Accessing powerpoint object programmatically using C#

I am accessing a ppt template in C# and creating a custom output programatically based on data. 我正在C#中访问ppt模板,并根据数据以编程方式创建自定义输出。

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 现在,以防万一,如果模板的类型为“ .ppt”,则确实存在上述使用的OLEFormat.Object ,如“ .pptx”的情况一样,则会出现以下错误

OLEFormat (unknown member) : Invalid request. OLEFormat(未知成员):无效的请求。 This property only applies to OLE objects. 此属性仅适用于OLE对象。

Not able to recognize it, I have searched msdn as well as other sites but no one is distinguishing '.ppt' and '.pptx'. 无法识别它,我搜索了msdn以及其他站点,但是没有人区分“ .ppt”和“ .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' 在以编程方式创建PowerPoint演示文稿的链接中,提到我们可以通过编程方式编写PowerPoint,我面临的问题是,当扩展名为“ .ppt”时,我能够执行相同的操作,而对于'.pptx',则我可以无法访问在模板中使用的图表和图形,因为在使用“ .pptx”的情况下,用于访问图表的OLEFormat.Object无法正常工作,我是否缺少支持“ .pptx”的dll,我目前正在使用'组装Microsoft.Office.Interop.PowerPoint.dll,v2.0.50727'

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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