private void button10_Click(object sender, System.EventArgs e) { string fileName = "d://a.ppt";
PowerPoint.Application pptApp = new PowerPoint.ApplicationClass(); PowerPoint.Presentation pptPre = pptApp.Presentations.Open(fileName, Microsoft.Office.Core.MsoTriState.msoTrue, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoFalse); PowerPoint.Slides mySlides = pptPre.Slides;
string[] strKeyWordList = {"无线"}; //要搜索的文本 try { /* for (int i=0;i<mySlides.Count;i++) { PowerPoint.Shapes myShapes = mySlides[i].Shapes; for (int j=0;j<myShapes.Count;j++) { if (myShapes[j].HasTextFrame == Microsoft.Office.Core.MsoTriState.msoTrue) { if (Microsoft.Office.Core.MsoTriState.msoTrue == myShapes[j].TextFrame.HasText) { textBox2.Text = textBox2.Text + myShapes[j].TextFrame.TextRange.Text; } } } } */ foreach(PowerPoint.Slide sld in pptPre.Slides) { foreach(PowerPoint.Shape shp in sld.Shapes) { if(Microsoft.Office.Core.MsoTriState.msoTrue == shp.HasTextFrame) { if(Microsoft.Office.Core.MsoTriState.msoTrue == shp.TextFrame.HasText) { textBox2.Text = textBox2.Text + shp.TextFrame.TextRange.Text; } } } } /* PowerPoint.TextRange oText = null; foreach(PowerPoint.Slide slide in pptPre.Slides) { foreach(PowerPoint.Shape shape in slide.Shapes) { foreach(string strKeyWord in strKeyWordList) { oText = shape.TextFrame.TextRange.Find(strKeyWord, 0, Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoTrue);
if(oText!=null) { MessageBox.Show("文档中包含指定的关键字 " + strKeyWord + " !", "搜索结果", MessageBoxButtons.OK); continue; } } } } */ } finally { pptPre.Close(); System.Runtime.InteropServices.Marshal.ReleaseComObject (pptPre); pptPre = null; pptApp.Quit(); System.Runtime.InteropServices.Marshal.ReleaseComObject (pptApp); pptApp = null; } }