Book Image

VSTO 3.0 for Office 2007 Programming

By : Vivek Thangaswamy
Book Image

VSTO 3.0 for Office 2007 Programming

By: Vivek Thangaswamy

Overview of this book

With the arrival of Visual Studio Tools for Office 3.0 (VSTO), developers can now program Microsoft Office from the .NET framework. There are huge books in the market that give loads of unnecessary information but are of no real help to brand-new Office developers. Wouldn't it be great to have a precise book that simply covers the basics and introduces programming Office 2007 with VSTO using the latest version of Visual Studio? This is that book. VSTO 3.0 for Office 2007 Programming shows you how to write Office 2007 applications with Visual Studio Tools for Office 3.0. Learn how to automate tasks in InfoPath, Word, Excel, Outlook, PowerPoint, Visio, and Project 2007 with greater programming power and flexibility than was available from the VBA language. With this book and the mastery of VSTO you will learn, Office will no longer be an application to you; it will be a platform for developing custom applications.VSTO 3 is the most recent version of VSTO, making use of Visual Studio 2008, and working with Office 2007. This book shows how VSTO puts Office automation into the hands of developers, allowing them to use the power of the .NET framework to automate Office applications thus increasing the speed of the applications, their security, and the opportunity to use other parts of the .NET Framework such as its data handling capabilities. This book builds a solid programming foundation in VSTO for brand-new Office developers. You will leave behind the world of VBA programming and take your first steps into the powerful and exciting world of using C# to create Office 2007 applications. Packed with examples and covering all the main Office applications, this book will have you creating fully featured Office extensions before you know it.
Table of Contents (11 chapters)
VSTO 3.0 for Office 2007 Programming
Credits
About the Author
About the Reviewers
Preface

Why VSTO 3.0?


VSTO is a simple, but powerful framework for Office solution development. The framework brings an amazing number of benefits to the hands of every Office developer—form controls, classes, granular security, server scalability, object-oriented features, integrity, easy deployment, and many others.

Safer managed code extensions

VSTO allows managed and unmanaged code to be seamlessly put together into the same .NET assembly. This allows the developers to retain unmanaged code that cannot be ported over to the .NET framework without completely re-writing it. The Microsoft Office document or workbook with a linked or referenced managed code assembly is said to have managed code extensions. Managed extensions can be created by using VSTO on Microsoft Excel or Word, which are similar to macros but are much safer. With VSTO, you can create a template that only needs to be loaded with data.

Data caching

Data caching, simply put, is storing data in memory for quick access. A Microsoft Office Word document or Excel workbook has a hidden control rooted inside it called the Runtime Storage Control, which stores cached data. VSTO provides data-caching capabilities as well as a ServerDocument class in C# that can be used by an application external to Office (for example, the Winform application) to manipulate the data cache without accessing the object model of Word or Excel.

Feature customization

VSTO 3.0 gives you great control in being able to customize Office applications with reusable classes. Unlike VBA developers, VSTO developers are not limited to the VBA function library. VSTO provides a wide variety of classes, objects, and events to build business solutions for Microsoft Office. Using VSTO, developers can customize features for Office applications. These can be as simple as a button on the application's Command bar or adding custom task panes, or as complex as a data report template with access to different data sources.

User Interface customization

VSTO provides Windows Forms controls that help you to develop a rich User Interface(UI) for your Office solution. By using a wide variety of control sets, VSTO developers can build rich data views for users. Each and every type of Windows Forms control has its own set of properties, methods, and events that make it suitable for different needs.

VSTO makes it easy to build rich User Interfaces by using controls inside the document and the Task Pane. For instance, you can create an animated one-button command to generate a form letter. For example, say a company has data content stored in its server, and a user wants to refer some content from the server while working in the document and without disturbing the current document view. Using VSTO, you can make the server content available inside the Task Pane of the document without interfering with the user's current work.

Smart tags

New for VSTO 3.0 and Office 2007, smart tags are strings that an Office application recognizes in a document. With Smart tags enabled, Microsoft Office Word attempts to recognize certain types of data in a document, visually indicated by a purple, dotted underline. Clicking on a smart tag brings up a list of possible actions for that particular data type. VSTO provides object models to Office developers, which can be used to create smart tags for documents and workbooks.

WPF support

Windows Presentation Foundation(WPF) controls is a technology product of Microsoft Corporation. WPF can be used to build a rich and attractive look and feel for the user. WPF can be used in VSTO development environment, which supports C# programming, whereas VBA lacks this support. VSTO's visual designer supports the use of Windows Forms and Windows Presentation Foundation controls. WPF provides a reliable programming model for building client-based and web-based applications, and presents a clear separation between the business logic and the UI.

Visual designers

VSTO provides visual designers for Office applications such as Word 2007, Excel 2007, and others that appear inside the Visual Studio IDE(Integrated Development Environment). Creating a form in the Visual Studio IDE is as easy as dragging and dropping the form into the Microsoft Office document. Developers gain access to many tools and features in Visual Studio's IDE, such as IntelliSense (Microsoft's implementation of auto completion in the Visual Studio IDE), drag and drop controls, and data sources. VSTO also provides the Ribbon Visual Designer that lets you customize the Office Ribbon and program it by using a simple .NET application-like programming model. The following image explains how IntelliSense helps developers using Visual Studio IDE.

Security improvements

The VSTO security model involves wide support from Trust Center in Microsoft Office and the Visual Studio Tools for Office runtime, which helps resolve the security issues common to VBA code. There are many disadvantages to the VBA security model. An abundant number of viruses are easily developed using VBA macros. To run VBA macros safely, you have to set the security to high on the user machine, and digitally sign the code. More importantly, these operations need to be performed manually by the user. In VSTO 3.0, the Security Model has been changed. VSTO builds the security policy that is required to run and debug your solution on your computer every time that you build a project. The Assemblies are signed before publishing—this is done by Visual Studio 2008. Preferably, you obtain a certificate from a globally-acknowledged Certificate Authority or from an internal Certificate Authority, if the solution is only for an internal solution, and sign the manifests using the signing properties page in Visual Studio. Later, you publish the solution to its appropriate location.

Maintainability

VSTO solutions developed for an Office system are easier to maintain. Updating the deployed solutions, changing the code, and updating a single assembly will help more resources doing the same thing in multiple copies of the same documents. All of the code will reside inside the assembly—a partially-compiled code library that contains the logical unit of code inside it as a single dynamic link library ( .dll) file. With macros, the script resided inside the Office documents. Whenever you wanted to update the code, you had to modify every single document that contained it. With VSTO 3.0, managing application-level add-ins can be done by simply changing the code and updating the single assembly, instead of doing the same thing for multiple copies of the same document.