C#操作PPT的问题,高手有木有 没有最nb的程序员,只有最nb的需求,帮你顶 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 c#操作powerpoint的一个例子2009-03-14 15:17摘自: http://c05.blog.hexun.com/7283637_d.html//实现PPT文本查找功能//关键代码private void searchPPT(string[] keyWordList,string pptFileName)//在指定的ppt文档中搜索keyWord { //Microsoft powerpoint 11.0 object library这个是所添加的引用 showMsg(lbShowMsg,"启动搜索"+pptFileName); //其中Presentation代表一个 PowerPoint 文档,Slide表示PowerPoint文档中的单张幻灯片 //TextFrame是幻灯片上的文本框,TextRange是文本框中的文本。 PowerPoint.ApplicationClass pa; PowerPoint.Presentation pp; pa=null; pp=null; try { showMsg(lbShowMsg,"尝试打开 "+pptFileName); //打开ppt文档 pa=new PowerPoint.ApplicationClass(); pp=pa.Presentations.Open(pptFileName, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoTrue,Microsoft.Office.Core.MsoTriState.msoFalse); PowerPoint.TextRange oText; int slideCount=pp.Slides.Count;//总的幻灯片数 foreach(PowerPoint.Slide slide in pp.Slides)//对每张幻灯片 { showMsg(lbShowMsg,"正在搜索"+pptFileName+" 幻灯片"+slide.SlideNumber.ToString()+"/"+slideCount); foreach(PowerPoint.Shape shape in slide.Shapes)//对所有的元素 { if(shape.HasTextFrame==Microsoft.Office.Core.MsoTriState.msoTrue)//如果此幻灯片中有文本框 { foreach(string keyWord in keyWordList)//对每组关键字 { oText=null; oText=shape.TextFrame.TextRange.Find (keyWord,0,Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoTrue); if (oText!=null) { string temp=pptFileName.Remove(0,pptFileName.LastIndexOf("\\")+1); string name=temp.Remove(temp.LastIndexOf("."),4); int index=slide.SlideNumber; lbResult.Items.Add(name+" 幻灯片"+index.ToString()+"/"+slideCount);//添加到搜索结果中 lbResult.Update(); resultText.Add(shape.TextFrame.TextRange.Text); continue; } } } } } } catch { } finally { //释放资源 if(pp!=null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(pp); pp=null; } if(pa!=null) { System.Runtime.InteropServices.Marshal.ReleaseComObject(pa); pa=null; } } } 可是如何将chart作出的图表放到PPT上并且数据改变PPT上也随之改变呢 救救救救命啊,水晶报表在没有vs的情况下怎么部署啊 还是ASP.NET前放置代码问题 全局变量问题,高手指点 怎么动态加载数据库菜单 经理让我在asp.net的程序里嵌套rtx的sdk的消息提醒发送示例,但我不知道怎么弄 付钱求一份完整OA系统[政府机关用](包含源代码及相关文档) 关于tree的postback的问题 数据库连接问题 菜鸟求解之身份验证 在局部刷新时,动态创建多个TextBox后,如何保存TextBox的Text属性的值? 很好,很不错的NET 学习资料 欢迎下载! 怎么接收接受(\n,\t,\r)(急)
2009-03-14 15:17
摘自: http://c05.blog.hexun.com/7283637_d.html
//实现PPT文本查找功能
//关键代码
private void searchPPT(string[] keyWordList,string pptFileName)//在指定的ppt文档中搜索keyWord
{
//Microsoft powerpoint 11.0 object library这个是所添加的引用
showMsg(lbShowMsg,"启动搜索"+pptFileName);
//其中Presentation代表一个 PowerPoint 文档,Slide表示PowerPoint文档中的单张幻灯片
//TextFrame是幻灯片上的文本框,TextRange是文本框中的文本。
PowerPoint.ApplicationClass pa;
PowerPoint.Presentation pp;
pa=null;
pp=null;
try
{
showMsg(lbShowMsg,"尝试打开 "+pptFileName);
//打开ppt文档
pa=new PowerPoint.ApplicationClass();
pp=pa.Presentations.Open(pptFileName,
Microsoft.Office.Core.MsoTriState.msoTrue,
Microsoft.Office.Core.MsoTriState.msoTrue,Microsoft.Office.Core.MsoTriState.msoFalse);
PowerPoint.TextRange oText;
int slideCount=pp.Slides.Count;//总的幻灯片数
foreach(PowerPoint.Slide slide in pp.Slides)//对每张幻灯片
{
showMsg(lbShowMsg,"正在搜索"+pptFileName+" 幻灯片"+slide.SlideNumber.ToString()+"/"+slideCount);
foreach(PowerPoint.Shape shape in slide.Shapes)//对所有的元素
{
if(shape.HasTextFrame==Microsoft.Office.Core.MsoTriState.msoTrue)//如果此幻灯片中有文本框
{
foreach(string keyWord in keyWordList)//对每组关键字
{
oText=null;
oText=shape.TextFrame.TextRange.Find
(keyWord,0,Microsoft.Office.Core.MsoTriState.msoFalse,Microsoft.Office.Core.MsoTriState.msoTrue);
if (oText!=null)
{
string temp=pptFileName.Remove(0,pptFileName.LastIndexOf("\\")+1);
string name=temp.Remove(temp.LastIndexOf("."),4);
int index=slide.SlideNumber;
lbResult.Items.Add(name+" 幻灯片"+index.ToString()+"/"+slideCount);//添加到搜索结果中
lbResult.Update();
resultText.Add(shape.TextFrame.TextRange.Text);
continue;
}
}
}
}
}
}
catch
{
}
finally
{
//释放资源
if(pp!=null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(pp);
pp=null;
}
if(pa!=null)
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(pa);
pa=null;
}
}
}
可是如何将chart作出的图表放到PPT上并且数据改变PPT上也随之改变呢