Two commonly used operations(两个常用操作)

Meets the preceding text(接上文)

It has been already introduced the common classes in my preceding text, and today, then let me introduce the operations of the two classes. Because my ability is limited, possibly i will write somewhat superficial, so welcome everybody to point out my mistakes, and i also welcome each position to discuss together with me.
1、Monitoring documents various events:

PowerPoint.Application CurApplication;
* monitoring opened or preserved documents, as follows

CurApplication.PresentationOpen +=

new Microsoft.Office.Interop.PowerPoint.EApplication_PresentationOpenEventHandler( this.PresentationOpen );

CurApplication.PresentationSave +=

new Microsoft.Office.Interop.PowerPoint.EApplication_PresentationSaveEventHandler( this.App_PresentationSave );


* writes the monitoring function, the above two monitoring homographic functions respectively are:

private void PresentationOpen(PowerPoint.Presentation presentation){}

private void App_PresentationSave(PowerPoint.Presentation Pres){}

so long as we places ours control in the corresponding function, then we can easily realize to their monitoring.
2、 enumerates all writings in a document
to analyze the operation,we can easily divides it into 2 more similar enumeration processes.
First one, enumerates in Presentation all Slide, its two pieces enumerate inside each Slide all Shape. Therefore, these writings then can be obtained very easily from this Shape.Concrete realizes are as follows specifically:

foreach (PowerPoint.Slide slide in this.Application.ActivePresentation.Slides){

foreach (PowerPoint.Shape shape in slide.Shapes){

string tmp = shape.TextFrame.TextRange.Text;

//Add your code here

}

}

like this, two simple operations completed. Although the operation is simple, but only you can use the application to be appropriate, then can realize fabulous effect. Anticipates everybody’s performance.

上文已经介绍了我常用到的一些类,而今天,则主要介绍这些类的两个操作。由于我能力有限,可能会写得有些肤浅,欢迎大家给予指正,也欢迎各位与我共同探讨。

1、监控文档各事件:

PowerPoint.Application CurApplication;

  • 监控打开、保存文档,如下

    CurApplication.PresentationOpen +=

    new Microsoft.Office.Interop.PowerPoint.EApplication_PresentationOpenEventHandler( this.PresentationOpen );

    CurApplication.PresentationSave +=

    new Microsoft.Office.Interop.PowerPoint.EApplication_PresentationSaveEventHandler( this.App_PresentationSave );

  • 写监控函数,以上两个监控对应函数分别为:

    private void PresentationOpen(PowerPoint.Presentation presentation){}

    private void App_PresentationSave(PowerPoint.Presentation Pres){}

只要将我们的操控放在相应函数中,便能轻松实现对他们的监控。

2、枚举一个文档中的所有文字

分析一下操作,容易将它分为2个较为相似的枚举过程。其一是枚举一个Presentation中的所有Slide,其二则是枚举每一个Slide里边的所有Shape。于是,这些文字便能很容易地从这个Shape中获得。具体实现如下:

foreach (PowerPoint.Slide slide in this.Application.ActivePresentation.Slides){

foreach (PowerPoint.Shape shape in slide.Shapes){

string tmp = shape.TextFrame.TextRange.Text;

//加入你的操作

}

}

这样,两个简单的操作就完成了。操作虽然简单,但只用应用得当,便能实现很不简单的效果。期待各位的表现。

Incoming search terms for the article:

~Charlie

Tags: , ,


No Responses Yet to “Two commonly used operations(两个常用操作)”

Leave a Reply