VSTO 3.0 for Office 2007 Programming
上QQ阅读APP看书,第一时间看更新

What is Microsoft VSTO?

VSTO is a platform for Microsoft Office solution development, built on top of .NET framework. The latest release is version 3.0. Starting with VSTO 3.0, developers have integrated Office clients into the Visual Studio designer and the .NET layers on top of the native object models.

What is Microsoft VSTO?

The image above represents how VSTO has been integrated with the Visual Studio 2008 environment. Now, the term "Office solutions" appears a lot. You may have questions like—"What exactly, is an Office solution anyway? What kind of Office solutions can be developed using VSTO?". Let's answer these questions.

An Office solution is a solution developed for Microsoft Office applications, including Word, Excel, InfoPath, Access, or PowerPoint. With the help of VSTO, developers can build Office solutions using what is known as managed code.

Managed code is program code that executes under the supervision of a .NET Framework Common Language Runtime. Programs in any programming language can be compiled using either managed or unmanaged code. Code that is built on the .NET framework is meant to be managed code. Managed code brings easy deployment to your VSTO solution, as compared to VBA(Visual Basic for Applications). VBA is a programming combination of Visual Basic associated with an integrated development environment for Microsoft Office applications.

Unlike VSTO, VBA doesn't support programming languages. VSTO gives you the full support of a programming language to build Microsoft Office solutions. VSTO helps you to build a secure and safe solution for your Office application. All of the VBA scripts will be stored inside the document for which you are programming, while VSTO brings you the new concept called document-level solutions and application-level solutions.

Using VSTO, Office developers can build solutions such as Add-Ins; Add-Ins are additional program components that can be added to Office applications by using VSTO. For example, Microsoft offers a few free add-ins for Office 2007 licensed users, such as the 2007 Microsoft Office add-in Microsoft Save as PDF or XPS—this add-in facilitates the saving of a document in PDF or XPS format. You can also customize existing Office application features, and you can program against existing options available in the Office application. Let's say you need to save or export all of the content from Microsoft Office Word 2007 to Microsoft Office Excel 2007 on the click event of a button placed on the toolbar, or during some action.You can create an add-in for this kind of activity using VSTO. This is one scenario where you can use a VSTO add-in for your Office solution development.

Before VSTO, Office developers had to use VBA, VB6, or C++ to create so called shared COM Add-Ins. All Add-Ins share the same address space, and if one fails, the host application or all other Add-Ins crash. Unlike VSTO, VBA code is written directly in the Office application's IDE and is compiled at run-time. All VBA scripts are stored inside the document for which you were programming. In VSTO, this is termed a document-level solution, where the solution is specific to the document for which it is deployed. Similarly, in VSTO, document level add-ins are delivered within a specific document. For example, let's say that you include functions in a specific Microsoft Office Word document—the functions are available only when you open that particular Word document. Document level add-ins are relevant only to Word and Excel. Document-level customizations are the VSTO version of VBA macros in Word or Excel.

VSTO introduces a new concept called application-level solutions. With an application-level solution, the solution is accessible for all documents processed through that particular application. You can build application-level solutions by using the application-level add-in for your solution development.

VSTO gives you two fully-supported programming languages in which to build Microsoft Office solutions that will run in all Microsoft Office applications—C#, VB.NET, or XML. As a VSTO programmer, you will need to have a basic knowledge of C# to program Office applications using C#. In this book, we will assume that you have a basic knowledge of C# concepts such as classes, namespaces, and methods. In addition, you should know the basics of XML.

Note

The following MSDN reference link will help you learn about .NET and C#: http://msdn.microsoft.com/en-us/vcsharp/aa336804.aspx

In most of the Office 2007 applications, Microsoft has used XML(Extensible Markup Language) as the standard format for data and UI processing. For example, InfoPath forms save data in XML format. C# brings you great programming support for XML and Office applications. Office already has built-in support for an XML-based customization model, of which VSTO takes full advantage. Using C# classes and simple XML, VSTO simplifies the connection between .NET, and the server and Office systems.

  • VSTO leverages two powerful technologies that you may be familiar with—C# and XML. C# is one of the most powerful programming languages supported by Microsoft .NET frameworks.
  • VSTO gives full flexibility to programs using C# and VB.NET programming language for Office 2007 applications.
  • You, as a VSTO programmer, need to have a basic knowledge of C#, in order to program Office applications using C#.

So, for instance, instead of having a Word macro that you need to run in order to create the document you want, you could simply transfer the information to a Word template and have Office create the document for you! VSTO thus provides data-caching capabilities.