VSTO Learning Note (ii) Excel object model

Source: Internet
Author: User
Tags microsoft outlook

Text: VSTO learning note (ii) Excel object model

The last time I learned about the development history of VSTO and the new features of its successive editions, it outlines the help and efficiency of VSTO for developers. Starting with VSTO 4.0, we will explore every aspect of VSTO development, and I am not in touch with VSTO for a long time. Given the importance of Excel throughout the Office family, start with Excel, followed by Word, PowerPoint, Outlook, InfoPath, and more. Since VSTO 4.0 is built on Office 2010, let's start with the new features of Office 2010, and note that it's only a beta version, and the official version may have functional tweaks.

Sample code Download

All sample code in this series is tested under Visual Studio Beta 2 + Office Beta

I. New features of Office 2010

Microsoft will officially launch Office 2010 in June 2010. Office 2010 brings many program improvements, maintains the Office 2007 XML file format, improves the Ribbon interface, and brings browser-based Excel, Word, OneNote, and PowerPoint as Office Web App services. and provide 64-bit office for the first time.

Office 2010 breaks the tradition of Microsoft and becomes the world's most well-known online Office tool, and the Web-based features in office 2010 are brand new, so problems can arise. While some companies plan to buy Office 2010, they also use free Google Docs and Zoho because of skepticism about Microsoft's new Office Online experience.

Office Word

Office Word 2010 enhances the Navigation Pane feature , which allows users to quickly switch to the beginning of any chapter in Navigation Pane (judging by the heading style), as well as instant Search in the input box. Chapter headings that contain keywords are highlighted. For example, search in Livesino.net:

Office Word 2010 also adds online real-time collaboration features that allow users to start Word 2010 for editing online documents from office Word Web App, and to see other users (including other contact information, IM, etc.) in the lower left corner , Office Communicator is required). When another user modifies a location, Word 2010 reminds the current user to synchronize. (Note: This feature also exists in some other Office 2010 programs)

In addition, users can insert other running software directly in Office Word, Office PowerPoint 2010, and Office 2010 programs such as Office OneNote 2010.

Office Excel

Office Excel 2010 has a new sparklines feature that allows you to draw a line, histogram, etc. directly in the cell based on the data selected by the user, with the Sparklines design panel for custom styling.

Office PowerPoint

In addition to adding more slideshow transitions and image processing effects, Office PowerPoint 2010 adds more video features that users can set (adjust) the start and end time clips video (see) directly in PowerPoint 2010. You can also embed the video in a PowerPoint file.

The slide panel on the left side of PowerPoint 2010 also has a new partitioning feature that allows users to categorize slide partitions or manipulate all the slides in the entire area. See the Default sections and Livesino sections in.

PowerPoint 2010 also adds a tool like the Format Painter – Animation Painter, which applies animation effects to other objects, using the same format brush. And the last time I mentioned the broadcast Slide show online slide play feature.

Other components of Office 2010, including OneNote, Access, InfoPath, and Publisher 2010, all contain new features and are already in the Ribbon UI but I'm not going to go into details.

Office Web Applications

Office Web Applications includes Word web App, Excel Web App, PowerPoint Web App, and OneNote Web app, supporting simple editing and real-time collaboration features, support IE, Firefox, and Safari. The specific content is described in the following article, the other is attached clearly as follows:

Office Mobile

Office Mobile 2010 includes the new version of Word Mobile, Excel Mobile, PowerPoint Mobile, OneNote Mobile, and Outlook Mobile that supports dialog mode (see, Source: Supersi TE).

The enterprise server side can also render Office documents for Enterprise mobile users to view Office documents on the phone, as well as BlackBerry and iPhone.

wzor.net leaked the Microsoft Office Professional Plus Technology Preview (x86, x64), while Ars Technica released the full set of Offi in the first time CE 2010. Although the interface has not changed much compared to Outlook 1 months ago, the latest TechED 09 and the leaked version of Office 2010 hint at some of the new features of Office 2010.

Windows 7 Jump Lists

On TechEd 2009, Microsoft demonstrated Outlook 2010 that supports the new features of Windows 7 jump Lists . When there are unread messages. The lower-right corner of the Outlook taskbar icon also includes an icon hint for a new message, such as. (via TechRadar)

Microsoft PowerPoint Live (broadcast Slide Show)

PowerPoint 2010 supports publishing presentation documents to PowerPoint Live or other online services so that other users can view the presentation in a browser similar to Apple iwork.com. And PowerPoint Live is likely to be part of Office Web applications .

The JCXP also gives Some of the new features of PowerPoint 2010 and Word 2010, such as PowerPoint features, a new PowerPoint transition effect, and a slideshow in PowerPoint.

In addition, theofficial Office 2010 team has confirmed that Groove has been renamed to SharePoint Workspace and that both OneNote and SharePoint Workspace will be included in the Pro Plus version.

I have installed the office Professional Plus Beta X64:

As described above, the naming of InfoPath and Groove has changed and the rest is unchanged. Personally feel that the biggest change in office 2010 is the support for online office, which is the trend of future development, the individual is optimistic. Other new features I will try it out in succession and will post in the next chapter to experience new features with VSTO 4.0来.

Second, the Excel object model

The object model is a set of objects that are provided by Office applications that control Office applications and are the core content of VSTO development. Where application is the topmost object that is responsible for the overall control of office, similar to the Application object in. Net WinForm and WPF, is the root object. Workbook (s) refers to workbooks, Worksheet (s) refers to worksheets, and chart (s) refers to various charts. The Sheets object is special, it contains objects of the worksheet or chart type, and range represents the range of cells you want to manipulate.

III. Primary intermodulation Assembly (PIA)

The managed assemblies that are used to interact with Office are called Office Primary intermodulation Assemblies (PIA).

PIA = Primary Interop Assemblies

Typically, a. NET technology called COM Interop is used to interact with the Office object model, and all Office objects are written in unmanaged code (c, C + +) and provide a COM interface. In order to communicate with these interfaces in managed code, you must use the wrapper to implement the co-operation between managed code and the Office unmanaged COM interface. The wrapper is a series of. NET classes, they are compiled into PIA assemblies. The reason PIA calls it "master" is because developers can develop their own wrapper IA (Interop assemblies), and unless there is a very special requirement, it is not recommended to use their own IA because it cannot interact with other Office solutions. It may also contain bugs that office has fixed.

The PIA is installed when the appropriate version of Office is installed, and it is recommended that you install Office Professional Plus Beta If you are developing VSTO 4.0. The Office PIA is installed in the GAC (GAC = Global Assembly Cache).

Most VSTO projects automatically add a PIA, and if you create other types of projects (consoles, class libraries, WinForm, WPF, and so on), you need to add the PIA manually.

microsoft.office.interop. Word.dll

TD style= "BORDER-BOTTOM:0.5PT solid; Border-left:medium none; padding-left:7px; padding-right:7px; Border-top:medium none; border-right:0.5pt solid "valign=" middle ">

Description

Assembly name

Name space

microsoft Office 14.0 Object Library

office.dll

microsoft.office.core

microsoft Excel 14.0 Object Library

microsoft.office.interop.excel.dll

microsoft.office.interop.excel

microsoft Word 14.0 Object Library

microsoft.office.interop. Word

microsoft Outlook 14.0 Object Library

microsoft.office.interop. Outlook.dll

microsoft.office.interop. Outlook

microsoft Graph 14.0 Object Library

microsoft.office.interop. Graph.dll

microsoft.office.interop. Graph

Microsoft.smarttags 2.0 Type Library

Microsoft.Office.Interop.SmartTag.dll

Microsoft.Office.Interop.SmartTag

When there is a dependency between the PIA, VS2010 automatically adds the necessary PIA.

Iv. Office Solutions

1. Office Automation Program (Office Automation executable)

Office Automation programs are office-independent programs that control and automate the processing of an Office application. such as consoles, class libraries, WinForm, WPF, and so on.

2. Office Add-ons (add-in)

An office add-in is a class in an assembly (DLL) that office can load and create when needed, and add-ons can run directly in the process of an Office application without having to run in a process separate from the Office application. Add-ons remain loaded throughout the entire life cycle of an Office application.

3. Office Document codes (code Behind on Office documents)

Office document code has been widely used in the VBA era and has been further enhanced in VSTO. Office document code can be customized for Office applications in some way, such as adding menu items that appear only in the current document, or triggering events when a document is opened.

4. Office templates (Office template)

Create the appropriate office template by using managed code.

5. Server document Mode

VSTO can run programs on the server side without opening Office applications and manipulate data that resides in Office documents, such as the cached data feature for VSTO, Excel Services for SharePoint 2007/2010, and so on.

6. OpenXML mode

Use the OPENXML API to manipulate the data in Office documents, combine XSLT, and so on into the desired document format. For an introduction to OPENXML please see another series of my blog: OPENXML study notes.

Five. Office Document code sample

As the main learning of the Excel object model, GU Office document Code model to do a few simple exercises, the rest of the model will be introduced in succession.

1. Create a new Excel Workbook project:

The default added references and project files:

2. Add two buttons and a Label control in SHEET1:

3. Add Event handling code:

Code         Private voidBtnpia_click (Objectsender, EventArgs e)
{
Excel.Workbook Book=  This. application.workbooks[1];
Excel.Worksheet sheet=Book . worksheets[1];//C # 4.0 new features, PIA dynamic import.
             This. Labmsg.text= "This is the result of the PIA call and the current sheet name is:" +sheet. Name;
}

Private voidbtn Get worksheet _click (Objectsender, EventArgs e)
{
This. Labmsg.text= string. Empty;
Excel.Workbook Book=  This. application.workbooks[1];

for (intI= 1; I<=Book . Worksheets.count; I++)
{
//C # 4.0 new features, PIA dynamic compilation.
                 This. Labmsg.text+=Book . Worksheets[i]. Name+ " ";
}
}

The new features of C # 4.0 benefit from the ability to convert without a display type, while the PIA will import and compile at runtime, noting that most indexes in VSTO start at 1 instead of 0.

4. F5 runs, the generated Excel will open:

5. Operation Result:

Vi. Summary

This first describes the new features of Office 2010, learns the basics of VSTO development, has a deep understanding of the PIA, and describes the differences between different Office solutions. Finally, a simple example is made with the Excel document code, which uses the new features of C # 4.0 to make the development of VSTO 4.0 more convenient and efficient. If you're not familiar with C # 4.0, you might want to take a look at the relevant articles in the garden to debug this sample code and install VS2010 Beta2 + Office Beta. Next time you'll continue to learn about Excel, we'll use VSTO to write an Excel custom formula that compares it to VBA.

VSTO Learning Note (ii) Excel object model

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.