[Vsto series] 1. vsto for Excel getting start!

Source: Internet
Author: User
  • Our goal:

In this series of articles, we will use some small examples to gradually learn vsto for excel, a technology that has been around for a long time, I rarely find more comprehensive or specific articles, except msdn.

I started this series on my blog. I wanted to consolidate my technical knowledge, and I also wanted to share my technical experiences with you, hope to gain more valuable experience!

The first part of this series has the following articles:

  1. Getting start (add-in level)
  2. Simple uidesign (Robbin)
  3. Batch operation (with an example of QQ contact export, add-in level) j
  4. Rich User-Defined UI interaction (add-in level)
  5. Deploy the add-in component to the client

In the second phase, we will make flexible modifications and adjustments based on the situation in the first phase. You are welcome to make a decision!

  • What is vsto:

Yes. What is vsto? In fact, many of my friends, including msdn, have provided a very good definition. Here I will not go to it. Please refer to the following URL for reference:

Reference: http://blog.csdn.net/v_jzho/archive/2007/09/29/1806904.aspx

Reference (Official comparison): http://msdn.microsoft.com/zh-cn/library/zcfbd2sk (V = vs.80). aspx

  

  • Excel Object Model:

Before learning about a development object, it is very important to understand the object model. So again, as shown in the following example, we have introduced the object model from msdn, all of which are in Chinese, I believe everyone can understand it. Please study with patience. After all, this is very important in the future!

Reference: http://msdn.microsoft.com/zh-cn/library/wss56bz7 (vs.80). aspx

  • Development Environment:

Now that we are working on development, we need to build the development environment. The following is an introduction from msdn. Here is a brief introduction, because when vs08 is installed and office2007 is installed, this development environment is basically complete.

Install design tools on Development computers

  1. Install the Office, including the main interoperability assembly. For more information, see How to: Install the main office interoperability assembly.
  2. Install Office 2003 SP1 or later. For more information, see Office 2003 Service Pack 1 website (http://office.microsoft.com/zh-cn/officeupdate/default.aspx ).
  3. Install vsto 2005 or Visual Studio team system, including the programming language Visual Basic or Visual C #.

By default, vsto 2005 is installed with Visual Studio team system When Visual Basic or Visual C # is installed.

  1. If Visual Studio is in English but uses non-English Windows Settings, you can install Visual Studio Tools
    For office Language Pack to view Visual Studio Tools for office in Windows
    The message of the running database. Visual Studio Tools for office language packs can be downloaded from Microsoft (http://www.microsoft.com/downloads/search.aspx? Displaylang = ZH-CN. This language pack is automatically installed in non-English versions of Visual Studio Tools for office.

If you install Visual Studio team system before installing office, you must repair the Visual Studio Tools for office Runtime Library by running the runtime Installation File (vstor.exe. For more information, see how to install the Visual Studio Tools for office Runtime Library.

  • The first add-in project:

Well, after a lot of preparations have been completed, I think everyone would like to reveal their skills. It is not very difficult to create an office project. For example, create an Office EXCEL add-in (external program) Project Based on C # language.

The following machine does not have the 03 office, but you can also use the 03 template for development. For convenience, I use the 07 template (though required. net 3.5 framework ......) Then, we can see that the project structure is as follows:

What is thisaddin. CS? Let me hear about it.

This thisaddin file is similar to an external program (addin) entry. All important operations, including object acquisition, must be performed here.

It is clear in msdn:

When
You create an Excel add-in project, Visual Studio generates a class,
Called thisaddin, which is the foundation of your solution. This class
Provides a starting point for writing your code, and it also exposes
The object model of EXCEL to your add-in.

Haha, it's no longer cool. Continue with our code. In the simplest way, we can see that thisaddin has a startup method. In this method, we mainly write some processing functions when the external program is loaded, for example, registering an event or initializing an object is as follows:

1 // register event 2 This. application. workbookbeforesave + = new Microsoft. Office. InterOP. Excel. appevents_workbookbeforesaveeventhandler (application_workbookbeforesave );

We have registered a Custom Event, which causes the plug-in to respond to us before saving the event. Then, in the thisaddin class, add the implementation function code of the event just registered as follows:

/// <Summary> /// Save the previous function code /// </Summary> /// <Param name = "WB"> workbook parameter </param> // /<Param name = "saveasui"> Save options </param> // <Param name = "cancel"> Can I cancel the operation? </Param> void application_workbookbeforesave (Microsoft. office. interOP. excel. workbook WB, bool saveasui, ref bool cancel) {excel. worksheet activeworksheet = (Excel. worksheet) application. activesheet); excel. range firstrow = activeworksheet. get_range ("A1", missing); firstrow. entirerow. insert (Excel. xlinsertshiftdirection. xlshiftdown, system. type. missing); excel. range newfirstrow = activeworksheet. get_range ("A1", missing); newfirstrow. value2 = "this text was added by using code ";}

So far, a simple add-in program has been completed. Let's start F5 together!

When debugging the program, open a blank working thin, and click Save. Note that the A1 value is filled. Indicates that the plug-in is running normally. This is the end of the first article. I hope you will have some gains. (Every article should be as short and competent as possible)

So far, a simple add-in program has been completed. Let's start F5 together!

When debugging the program, open a blank working thin, and click Save. Note that the A1 value is filled. Indicates that the plug-in is running normally. This is the end of the first article. I hope you will have some gains. (Every article should be as short and competent as possible) -- Don't go away, there will be a small tips later ~~~

Small tips:

After each debugging, we 'd better develop a good habit of recycling! Otherwise, these plug-ins may be inexplicably faulty. I cannot tell you the specific reason, so let's talk about recycling habits first.

How to recycle it? Simple: "Clear Solution" and "Clear Project". In this case, OK!

Author: Jack fan (Beginner's blog of. Net CF/. Net)
Source: http://longqi293.cnblogs.com
You are welcome to browse and repost this blog post, but this statement must be retained without the author's consent, and the original article connection is clearly provided on the article page. In the reference article, I will indicate the source of the reference article and respect the copyright of others. If you find that I infringe your copyright, please contact me in time.
For more articles, see [stick] index stickers-mobile development (continuously updating)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.