Vsto + winform + WebService + WCF + WPF example

Source: Internet
Author: User

Some time ago I went to the library to borrow a book and accidentally found this book named "a new generation. net Office Development excel ", the title is more interesting, let's take a look. after reading it, I found it really good. it mines the parts that we often ignore in office products. comparison table, pivot table, etc. next, based on my notes on this book, let's take a look at what vsto looks like when it was secretly released by Microsoft and abandoned by us? This book only applies to excel, so this is the focus, but there is also an example based on word.

We first create a windowapplicationProgramAnd then introduce the necessary class library.-1.

Figure-1

The purpose of creating windowapplication is to familiarize yourself with the syntax of office operations.CodeTo operate the Excel file, the code is relatively simple and will not be detailed here, as shown in-2.

Figure 2

Notes

1. When cyclically obtaining the cell value, we can put the value in a two-dimensional array first, and then obtain the cell value from the two-dimensional data, the effect will be improved to several levels. We recommend that you use

2. After use, or when the form is closed, you must call the app1.quit () method. If you operate the Excel file directly, you still need to control and process the process, because there are risks.

The above describes the most basic operations, including cell values and values.

Let's take a look at a vsto program. It seems that the vsto program environment needs to be patched, and the specific situation cannot be remembered. let's talk about my environment vs2008 SP1 + net3.5sp1. After the environment is set up, we will directly create a project file with my office version 2007. -3. if it does not appear, resolve it on your own. there are also a lot of posts in this aspect in the blog Park. It's okay to search for them.

Figure-3

The project file here is excelworkbook1, which demonstrates the following functions.

Function 1: Enter the sheet1 form. The data is taken from sheet2 and the cell drop-down menu function (no control is used) is implemented. Other cell values are generated based on the selected items in the drop-down menu, the unit price and quantity are calculated to generate the cell value of the amount. -4

Figure 4

Figure 5

Function 2: use the code to call the printing function. It is the printing function of Excel itself.-5 shows

Function 3: generate a calendar year

Function 4: Obtain the system color. The color is taken from the system. Drawing. knowncolor [] object.

Function 5: Obtain the image. Note that the image is not a chart.

Function 6: add the winform control. Correct, It is the winform control (Be sure and be sure). You can also dynamically create it. You can refer to the Code for reference.

Function 7: adds a widget, as shown in-6. it is estimated that this is rarely used in the past. I only know after reading this book. it is used to expand the functions of office project files. for example, you can use this control to drag some winform controls to do things that cannot be done by office project files. for example, you can place some video or audio files to be played in Excel. use this control to call the player or display its details. the most common scenario is the document page. use Excel to load list data. This control is used as the document page. It is quite simple to make another save and cancel button. controls-7

Figure 6

Figure-7

The example file of excelworkbook1 is just a test. The example below is more powerful. I admire Microsoft and make things simple. It's just that we keep things complicated by ourselves.

Continue to read the project file of excelworkbook3, as shown in project layout-8. This project file contains the following functions:

Figure-8

It includes the following functions:

Function 1: added cell annotation in code mode.

Function 2: the menu bar, toolbar, and events can be dynamically added.

Function 3: Change application-level attributes

Function 4: replication at the cell or sheet level

Function 5: A chart. The entire sheet is a chart, which has the same level as the sheet. The data source can be taken from an Excel file or an external data source.-9

Figure-9

Function 6: A chart. A sheet contains data and charts, as shown in-10.

Figure-10

Function 7: Pivot table. haha, this function is a bit like a function in Bi. drill down the data under it. -11. the left part is the raw data, the right side is the data that has been viewed, And the generated data, the field column can also be self-displayed/hidden. you can also generate a chart based on the perspective data, which is also included in the sample code. You can customize the parameters. this function can be used in a function system with the decision function, such as the sales volume of a department and the daily income expenditure table of a department. using this Excel function is much easier than those chart controls. referencesArticleThe address is as follows:

Http://www.cnblogs.com/cameo/archive/2008/12/01/1344956.html

However, there is a technical point that has not been studied clearly. It is the vsto project file. After the release, how can we display it in the web program? If you have any children's shoes, please click here.

Figure-11

Function 8: Call the WebService function. at first, it was very complicated. after the attempt, we found that the WebService method called by winform is the same. -12. the WebService address I found on the Internet seems unstable and sometimes cannot be connected. you can find another one by yourself.

Figure-12

The above is an example of the Excel section. the following describes a more important plug-in Function Based on word. it uses the WPF and WCF technologies. it contains three project files. -13.

The reference address for this project is http://msdn.microsoft.com/zh-cn/magazine/cc163292.aspx below

You can download the sample demo directly. I wrote the code myself! Note the release of WCF!

Figure 13

The function of the word plug-in is to load a group of images to the Word documents in a slide manner, select an image, and display the image description in the Word documents. the widget that displays images is WPF, which is used in the winform control ). put the image description text in an XML file and use the WCF method (more interesting ). first look at the final one, as shown in-14.

Figure 14

Briefly describe the functions of the project

For the wcfservicelibrary project, the function is to define the WCF Service. It means that this class library is from net2.0 and can be used to load the relevant class library of WCF. I always thought it was only 3.5.

Wpfcontrollibrary is a WPF user control, and the class library is 3.5. After the WPF control is created, how can we convert it into a winform control? You can create a winform user control and then load the WPF control.-15

Figure-15

The wordaddin1 project file creates a type of project file. the winfisheyebywpf control encapsulates the winform custom control of the WPF control. the code in is not detailed. let's see it for yourself. It's not very complicated. people with vsto basics seem to be easier to understand!

Well, there are so many examples here. The reason why we want to talk about a vsto article is that it can actually do a lot of things for us, but we usually ignore it, only Excel files are used to store data. if you use the imported and exported data properly, you can develop a management system based on the Office documents. The function is no inferior to the winform or webform developed by.

During the Dragon Boat Festival, I went to eat dumplings and wish you a happy holiday!

 

Sample Code

Examplevsto

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.