Would You like to Share!

VSTO 之 初始篇

by Charlie on May.13, 2008, under VSTO, Hits 921

安装完VSTO,便进入了它的使用过程。这里,只简单的介绍一下VSTO工程的建立及简单的开发。具体开发及技巧,将在以后做出介绍。在这里,我用是VS2005+Office2007,语言为VC#。

安装完VSTO后,打开VS2005,单击打开新建工程项,便能看见如下窗口。

VSTO in VS2005

以PowerPoint为例。新建一个“PowerPoint 外接程序”工程。这是,将产生一个ThisAddIn.cs文件。里边分别由如下两个函数

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}

private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}

于是,每回PowerPoint被打开时,都会运行private void ThisAddIn_Startup(object sender, System.EventArgs e)。后一个函数则是析构函数。这样,只要将咱们的代码加入第一个函数,便实现想要的效果了。

这里还是举一个简单的例子。每回打开一个文档时,对这个文档进行关键字的搜索。代码大致如下,其中细节问题会在以后有所介绍。

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{

//Monitor the event of Open a Presentation and save
this.Application.PresentationOpen +=
new Microsoft.Office.Interop.PowerPoint.EApplication_PresentationOpenEventHandler(this.PresentationOpen);

}

接下来,在写这个函数。。。

private void PresentationOpen(PowerPoint.Presentation presentation)
{

foreach (PowerPoint.Slide slide in this.Application.ActivePresentation.Slides)
{
foreach (PowerPoint.Shape shape in slide.Shapes)
{
//To see whether the Str_KeyWord exist in the Presentation
string tmp = shape.TextFrame.TextRange.Text;
int i = tmp.IndexOf(Str_KeyWord);
if (-1 != i )
return true;
}
}

}

这样,咱们的简单的搜索就完成了。。。

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • TwitThis
  • BlogMemes Jp
  • De.lirio.us
  • blinkbits
  • Slashdot
  • Symbaloo
  • TailRank
  • Webnews.de
  • Reddit
  • Yahoo! Buzz
  • YahooMyWeb
:, , , ,

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!