Posts Tagged ‘VSTO’

Developping Ribbon(设计Ribbon)

Nearly the end of the term, coupled with last weekend’s Northeast ACM,
I am afraid not much time to write the VSTO. So taking advantage of this two-day
idle, wrote this article.

        While developping a software, we always want
 a human surface, VSTO projects versa. And I have
said before, these articles is mainly for the users
of VS2005, since VS2008 users do not have to charge
too much effort, VS2008 enables them design a Ribbon
 easily, Figure:



 As an example to VS2005 + PowerPoint2007 (the same
to Word, Excel),user just need to create a Add New
Item menu to create a new Ribbon. This creates two
files in your project:one for Ribbon definition
and one for the Ribbon codebehind.Just simply edit
the methods generated in the Ribbon1 class to
handle these callbacks,you will see a new Ribbon,
a lovely big smiles.

Follow are the content of the XML file:

<customUI xmlns=
"http://schemas.microsoft.com/office/2006/01/customui"
onLoad="OnLoad">
  <ribbon>
    <tabs>
      <tab id="myOwnTab" label="PowerPlugin" >
       <group id="Group_Options" label="PowerPlugin">
         <toggleButton id="ButtonPassOn" size="large"
 label="PowerPlugin On" screentip="我的按钮屏幕提示" 
onAction="OnToggleButton" imageMso="HappyFace"/>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

   Here, it is not difficult to see the structure
of our Ribbon:a tab whose id is myOwnTab, a group
whose id is Group_Options and a toggleButton whose
id is ButtonPassOn.

<toggleButton id="ButtonPassOn" size="large"
label="PowerPlugin On" screentip="我的按钮屏幕提示"
 onAction="OnToggleButton" imageMso="HappyFace"/>

Analysising this statement, we can easily guess the
role of onAction. However, from where could we see
the statement of OnToggleButton?

Back to our source, we can easily find this function.
public void OnToggleButton(Office.IRibbonControl control, bool isPressed){

}
Thus, the whole process is relatively clear of.

In addition, I would like to introduce several of my control commonly used.

name

Ope1

Ope2

Box OnAction
dropDown onAction=

“HandleIndexedAction”

labelControl onAction
editBox getText=”getText” onChange=

“HandleOnChange”

button onAction=”getText”

public string getText(Office.IRibbonControl control){

}
public void HandleOnChange(Office.IRibbonControl control, string text){
}
public void HandleIndexedAction( Office.IRibbonControl control,
string selectedId, int index){
}

   期末将近,再加上周末的ACM东北赛,恐怕无太多时间再写VSTO了。于是
趁着这两天的空闲,写下这篇文章。

   开发一款软件,我们往往希望能有一个人性化的界面,VSTO的项目亦是
如此。当然,我以前说过,这些文章主要是针对VS2005的用户的,用VS2008
的用户则不必费太多功夫,VS2008中能直接设计器扩展Ribbon,如图:

 
        以VS2005 + PowerPoint2007为例(Word、Excel等类似),用
户倘若要新建一个加载项只需新建类中新建一个功能区支持。这时,将会产生
两个文件,一个Ribbon XML文件,一个Ribbon的源文件。只要按照提示将部
分代码注释取消便能在我们的powerpoint中看到一个新的加载项,一个可爱
的大笑脸。

        Ribbon XML文件的大致内容如下:

<customUI xmlns=
"http://schemas.microsoft.com/office/2006/01/customui"
 onLoad="OnLoad">
  <ribbon>
    <tabs>
      <tab id="myOwnTab" label="PowerPlugin" >
        <group id="Group_Options" label="PowerPlugin">
            <toggleButton id="ButtonPassOn" size="large"
 label="PowerPlugin On" screentip="我的按钮屏幕提示"
onAction="OnToggleButton" imageMso="HappyFace"/>
        </group>
      </tab>
    </tabs>
  </ribbon>
</customUI>

        从这儿,我们不难看到我们的Ribbon的构造,是由一个
id为myOwnTab的tab,一个id为Group_Options的group及一个
id为ButtonPassOn的toggleButton构成。其中,tab就是一个
选项卡,计上图中标为的PowerPlugin的选项卡;group也是一个
容器,便是陈放大笑脸的那个容器了;而toggleButton便是那个
大笑脸。

 <toggleButton id="ButtonPassOn" size="large"
 label="PowerPlugin On" screentip="我的按钮屏幕提示"
onAction="OnToggleButton" imageMso="HappyFace"/>
        分析这个语句,我们可以很轻松地猜测到onAction的作用。
但是,OnToggleButton这个事件又是在哪儿声明的呢?

        回到我们的Ribbon的源文件,在这我们不难找到这个函数。
public void OnToggleButton(Office.IRibbonControl control,
 bool isPressed){
}
        于是,整个过程也相对明晰了。
        另外,我再介绍几个我常用的控件及其处理函数。至于其他
控件,用户可自己尝试或查阅相关资料。

name

Ope1

Ope2

Box OnAction
dropDown onAction=

“HandleIndexedAction”

labelControl onAction
editBox getText=”getText” onChange=

“HandleOnChange”

button onAction=”getText”
public string getText(Office.IRibbonControl control){
}
public void HandleOnChange(Office.IRibbonControl control, string text){
}
public void HandleIndexedAction( Office.IRibbonControl control,
string selectedId, int index){
}

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;

//加入你的操作

}

}

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

VSTO常用类(Commonly used classes)

Both English version and Chinese Version

Since I’ve got several projects on hand,I’ve no too much time writting the blog.So just write casually!

Today,I just want to introduce some classes commonly used in mine project,and relations between them.

As I said before,my projects temporarily mainly aims at PowerPoint.Regarding the PowerPoint VSTO project,each time when one project is opened,there will produce a PowerPoint.Application object,in which, there are an ActivePresentation object and an ActiveWindow object.Each documents, is a Presentation.Obviously, ActivePresentation is the current documents.Now,I will give some classes commonly used in my project,and relations between them:

Class Relation
in which, SlideRange is the Slide set selected currently;easy to guess,ShapeRange is currently selected Shape set.
With these sets, we may enumerate obtain each element, for example:
foreach (PowerPoint.Slide CurSlide in CurSlideRange)
Thus, then can cselect all the element the enumeration.
In shape demonstrated the ordinary text,is stored up in TextEffect.Text.

And,through to the Presentation detection,we can detect the commonly used event in PowerPoint, like open presentation, preserve presentation, slide show and so on.You can turn to the first several articles specifically for codes.
I’ve to stop here today, if had any introduction not clear,contact me.
最近,手头上有几个项目,没太多时间写博客,随便写写罢!

今天,主要想介绍一些在我的项目中常用到的类,及他们之间的关系。

前面已经有过些介绍,我做的项目,暂时来说主要是针对PowerPoint。对于PowerPoint的VSTO项目来说,每个项目打开时都会应一个PowerPoint.Application类。这个类中,我常用到的是ActivePresentation和ActiveWindow。每一个文档,都是一个Presentation,很明显ActivePresentation便是当前文档。

以下,给出我的项目中用到的类,及其关系:

Class Relation

其中,SlideRange为当前选中的Slide集合;很容易猜测到ShapeRange为当前选中Shape集合。有这些集合,我们可以枚举获得每一个元素,如:foreach(PowerPoint.Slide CurSlide in CurSlideRange)。这样,便能完成对选中元素的枚举。

一个shape里显示的普通文本,储存在TextEffect中的Text里。

另外,通过对Presentation的侦测,我们能够侦测到PowerPoint的常用事件,如打开,保存,播放等。具体可以翻查前几篇文章。

今天就介绍到这儿了,如果有什么介绍得不清楚的地方,还希望大家多提醒我。

教育反馈系统(Education feedback system)

中英文版 Both Chinese version and English Version

寒假时接到一个项目,是关于教学反馈方面的。这个工程大致意思如下:

课堂上,老师为了便于掌握学生的学习情况,往往需要对学生的一些数据进行剖析。但单纯的举手什么的有时候很难满足老师们的需要。于是,便诞生了我们这个项目。通过计算机的处理,而列出一些数据,这样便方便老师掌握学生动态了。

具体实现,我们想设计这么一款软件,通过它老师能够设计一些题目,并给每个题目都赋一个答案。上课时,通过蓝牙或红外或许学生的输入,再处理这些输入并给出老师们想看到的条行图等具体数据。软件还能设置为记名答题和不记名答题两种模式。这样,便能便能对它的功能进行扩展。利用这款软件,用户们还能对被访问者的一些隐私内容进行调查;或者能在辩论赛等场合,用做抢答器或评委打分器。

考虑到Office使用的普遍性,我们又想将这款软件开发成PowerPoint 插件。老师只需要在需要添加题目的地方,使用我们的插件设置密码等项。这样老师便能能够正常编写这个文档,正常排版,而不用在我们的界面上勾画。

对于这个项目,由于某些问题,不便多说,望请谅解。若各位对这个项目有什么好的建议或意见,欢迎联系我。

Last winter vacation i receives a project,which is about the teaching feedback system. This project approximate meaning is as follows:
In the classroom, teachers for usually wanna keep abreast of student’s study situation,and they often need to carry on the analysis to student’s studying result. But pure raising hands to answer questions is like to be somewhat difficult to meet teachers’ needs. Therefore,our project was born. Through computer’s processing, and then lists some datas, througn these datas then teachers are able to grasp the student situation.
And the concrete implementing plan is as follows: we want to design such a software,which can design some questions endowed with an answer by the teachers.When attending the class,students could make use of the blue tooth or the infrared equipment to input the answer,then transform the datas to computer to process.After the datas analysed by the computer teachers can be given the strip good chart which teachers want to see. The software can also establish to record with a name or with no name two kind of patterns payable to bearer. Thus,we can then be able to carry on the expansion to its function.
Given the Office Suits are used so universally, we want to devilop a PowerPoint plug-in unit. Teachers only need to increase the topic goal place, uses our plug-in unit to establish the password and so on item. Then teachers can be able to compile this documents normally, normal typesetting, but do not use on ours contact surface outlines.
Regarding this project as a result of certain questions,i can’t talk more inconveniently so requesting your forgiveness. If everybody has any good suggestions or the opinions to this project, feel free to get in touch with me.

VSTO进行时––开发日志之三(VSTO Development diary III)

接上文 http://www.5ushare.com/vsto/vsto%e8%bf%9b%e8%a1%8c%e6%97%b6%e2%80%93%e2%80%93%e5%bc%80%e5%8f%91%e6%97%a5%e5%bf%97%e4%b9%8b%e4%ba

已经是Office数据安全工程的第三天了,工程也已经完成了三分之一,值得欣慰的是工程最繁琐的阶段过去了。

下边,向各位具体介绍工程的进度,各位如果有什么意见或建议,随时可以联系我。

现在,实现的主要内容是打开文档时,读取当前模式及模式具体信息。当用户登录时(为设密码用户打开文档时),根据模式储存的信息,回推出文档内容,并显示。另外还做了的就是,将选定slides、shapes中的shape隐藏。

没实现的部分,其一是模式的管理,如模式的新建,删除与选取编辑;其二就是用户保存时,模式信息的储存。还有就是系统热键的注册。

在数据的储存方面,我想采用的是一个shape来保存密码,当前模式及各模式的具体信息。其中,储存密码的shape的Name用于标记是否文档已经设置了密码,AlternativeText储存密码。另外,将会有一系列的shape来储存相应模式的信息,它们的信息都储存都shape的AlternativeText中。一下给出两个储存信息的模板如下:

< action = hide ShapeName = aaaaa SlideIndex = 1 >

<action = replace ShapeName = aaaaa SlideIndex = 1 word = aa NewWord = vgv >

今天暂且写到这里,欢迎有兴趣的朋友与我联系。

It’s the third day for the “Office Data Security” project,and the project have been completed 1/3.And i feel very satified because the most difficult stage has passed.

And then,i will introduce the concrete process to all of you.If anyone of you have any problems ,feel free to contact me.

At present,”when open the document then read the current parttern and the concrete information” part has been came true.When users register logged in,according to the pattern storage’s information,returns the documents content,and show it.

In addition,what i have done is make the part choosed dideaway.And now we also have three main problems:the first one is the pattern management,like pattern newly built,deletion and selection and edition;
the second one is the parttern information’s storage when users save the document;the third one is the system hot key’s registration.
In data storage aspect,what i wanna use is preserve the password,current pattern and various patterns concrete information by a shape.The Name in the shape is used to identify whether the document has been tagged.And the AlternativeText file is used to storage the password.
Give two templates of the information storaging to as follows:

< action = hide ShapeName = aaaaa SlideIndex = 1 >

<action = replace ShapeName = aaaaa SlideIndex = 1 word = aa NewWord = vgv >

It’s over today,welcome the friends who is instrsted to get in touch with me.

VSTO Installment

View Chinese version 中文版 http://www.5ushare.com/vsto/vsto-%e4%b9%8b-%e5%ae%89%e8%a3%85%e7%af%87.html

The VSTO request VS and Office ,VS may be the VS2005 or VS2008.And Office also has Office03 or Office07 that is
available.
So long as corresponds installment corresponding VSTO could use.It is noteworthy that between Office03 and 07
has the big difference, therefore two kind of VSTO cannot use in the same period.

You can download the VSTO at at Microsoft’s officials on-line
http://www.microsoft.com/downloads/details.aspx?FamilyID=f5539a90-dc41-4792-8ef8-f4de62ff1e81&displaylang=en
After installment, open VS2005, then you could see VSTO in the initial page.
STO project establishment is also very simple, only need open the new construction window.
Then you can see the Office node in VB or VC#,
then you could establish corresponding PowerPoint or Word and so on project. As for project running,
when you open procedures and so on PowerPoint, transfers your procedure automatically.
 The actual content, will later have detailed elaboration

Begin to VSTO

see in Chinese version  中文版 http://www.5ushare.com/vsto/vsto-%e4%b9%8b-%e5%88%9d%e5%a7%8b%e7%af%87.html

After installed VSTO,then you can use it.Here, i only give a a simple introduction VSTO project establishment and simple development to you.The concrete development and the skills,i will make the introduction later.
The tools i used are VS2005 and Office2007 ,the programming language is C#.
If you have installed the VSTO.Open VS2005, and then click the new project item,you can see the following window.

VSTO in VS2005
Take the PPT as the example.Newly built a“PowerPoint external connection procedure” project.
This will produce a ThisAddIn.cs document.Inside separately by following two function

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
}private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
Here cites a simple example. Returns every time when opens documents, to this documents
carries on the key words the search.The code is approximately as follows, the detail question will have the introduction in later.

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);

}
Then, write this function .

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;
}
}

}

 

Thus, our simple search completed.

VSTO进行时––开发日志之二(VSTO Development diary II)

接上文(Meets the preceding text ) http://www.5ushare.com/vsto/vsto%e8%bf%9b%e8%a1%8c%e6%97%b6-%e5%bc%80%e5%8f%91%e6%97%a5%e5%bf%97%e4%b9%8b%e4%b8%80vsto-development-diary.html

今天,主要针对这款软件的UI进行了设计。但由于未知的错误,无法解决加载项中的问题。

于是,我便对UI进行了修改。现UI大致如下,在加载项中添加了一个按钮,当用户点击这个按钮之后,便打开了程序的主窗口。主窗口有两个选项卡,一个用于用户密码登录或密码设置;另一个用于具体的控制。

下 面,我再简单的介绍一下软件运行的基本流程。首先,打开一个文档。这时候,程序将自动查看文档,获取是否保存有密码的信息。如果有密码,则再根据其他要 求,如隐藏某些文字,加密某些名字;如果没有,则正常浏览。使用期间,用户可以打开我们的窗口,来给一个文档设置密码或者更改密码;对于有权限的用户,还 可以打开控制选项卡。在控制选项卡中,主要也由两部分构成。其一是,隐藏或者显示某些文字;其二则是,对某些关键字的特殊,如加密或者显示时替代为其他内 容。用户使用过程中,还可以通过某些热键来控制显示模式。如,按两下ctrl以开启或关闭数据保护模式。

程序的具体实施方面,已大致完成了UI,具体控制方面则还没开始做。各位看了以上内容,如果有什么想法,可以联系我。

Today, i mainly aimed at designing the UI of the software.Because of some unknown mistakes, the inextricability Add-in could not load normally ,then I have to make the revision to the UI.

I layed a button in the Add-in.After the user clicked this button, there shows our main window. The main window has two option cards, one is used in the user password registering or the password establishment; Another is used in the concrete control.

And then , let me make a simple introduction about the basic flow. First, users open a document. At this time, the procedure will examine the documents automatically, gains whether it has set the password information or not. If it has a password, then acts according to other requests again, like hides certain writing, encrypts certain names; If not, then glances over normally.In the using period, the user may open our window, gives a documents establishment password or change the password; Regarding has the jurisdiction user, may also open the control option card. By controlling the option card, also by two parts of constitutions. First, the hideaway or demonstrates certain writing; Its two pieces are, to certain key words specialness, like when encryption or demonstration substitutes for other contents. When the users are using it ,they can also control the display mode through certain hot keys. Like, opens or the closure data protection pattern by pressing twice ctrl.

The procedure’s concrete implementation aspect, has completed UI approximately. Each position looked at the above content, if you have any idea, feel free to contact with me.

Incoming search terms for the article:

VSTO进行时–开发日志之一(VSTO Development diary)

最近,又接到了一个VSTO项目。主要是关于Office数据安全方面的。大致如下:

假如,我写了个文档,里边有些隐私内容并不想让别人看,但无奈,我的文档又必须给别人演示。而我想做的正是这么一个插件,通过他,我可以把文档的部分内容加密隐藏,这样别人就看不着了。即使看着了,他也不知道什么意思。这款插件,我想针对WORD来做,因为WORD应用相对普遍,对这类需求也相对更大。

今天,主要从技术层面上分析了一下,解决了如何去除关键字等具体技术。具体算法,由于这软件的特殊性,不便多说,望请谅解。。。

Recently, i have received a VSTO project which is mainly about the Office data security aspect.    Approximately as follows:if , I have written some documents, inside some privacy content does not want to let others look, but my documents must be showed to others. What I want to do is precisely such a plug-in unit, through which I may make the part of the doc hide away so that others aren’t able to see it. Even if they can look it ,they also do not know the meaning of it. This plug-in unit is mainly for WORD ,because the WORD is relatively common and its demand is bigger.
So today,i mainly have analyzed from the technical stratification plane about how to removed the key words and so on.About the concrete algorithm, given the software’s particularity, i’m incoveniently to talk about more.
Please waiting for my next one……

VSTO 之 初始篇

安装完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;
}
}

}

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

Incoming search terms for the article: