How to Help Your Business Become an AI Early Adopter
In my last article, "Using Visual Studio Tools for Office in Visual Studio 2008," you had a look at the new features of Visual Studio Tools for Office (VSTO) that are shipped along with Visual Studio 2008. You also read a brief discussion on the previous versions of VSTO and went through a walkthrough with the new version to create an "Actions Pane." With this article, you will see a brand new feature of VSTO 2008 that allows the developer to integrate his components directly with the Ribbon interface. You will see what the Ribbon interface is all about and why it is new and special to Office 2007.
For years, people have been used to the two custom toolbars located at the top of Word, Excel, Access, and PowerPoint. Outlook is the only application in Office 2007 that does not have the Ribbon interface. In previous releases of Microsoft Office applications, people used a system of menus, toolbars, task panes, and dialog boxes to get their work done. This system worked well when the applications had a limited number of commands. Now that the programs do so much more, the menus and toolbars system does not work as well. Too many program features are too hard for many users to find.
Microsoft adds new features to each release of Office and makes it more sophisticated and complex than the previous version. With the drawback as explained above, Microsoft had to rethink its strategy when working on this version of Office. So, it completely revamped the entire look and functionality of Office (which was released in late 2006 and named Office 2007). It brought the concept of the Ribbon in Office 2007.
In the Office Fluent UI, the traditional menus and toolbars have been replaced by the Ribbon—a device that presents commands organized into a set of tabs. The tabs on the Ribbon display the commands that are most relevant for each of the task areas in the applications. For example, in Office Word 2007, the tabs group commands for activities such as inserting objects like pictures and tables, doing page layout, working with references, doing mailings, and reviewing. The Home tab provides easy access to the most frequently used commands. Office Excel 2007 has a similar set of tabs that make sense for spreadsheet work, including tabs for working with formulas, managing data, and reviewing. These tabs simplify accessing application features because they organize the commands in a way that corresponds directly to the tasks people perform in these applications. At the time of publishing Office 2007, Microsoft included some enhancements in VSTO and named it VSTO 2003 SE. This included some functionality to enable the programmer to add his own functionality to the Ribbon Interface. But, this wasn't easy for the average developer; he needed some special skills to get a firm understanding of the whole picture.
Revamped Features of VSTO in Visual Studio 2008
With the release of Visual Studio 2008, Microsoft revamped the features in VSTO and released a new version VSTO 3; it is an integral part of Visual Studio 2008 and gives developers a new powerful tool to develop applications directly for the Ribbon interface with the simple ability of dragging and dropping user controls.
Here, you will walk through an example of developing your custom control and displaying it on the Ribbon Interface. This will normally appear in the last tab of the application, namely Add-in. Before you start coding, see why your application will end up in the Add-in Tab. When Microsoft was working on the design of Office 2007, it didn't want to break legacy applications and custom add-ins written for previous version of Office. So, it made a rule that all custom add-ins and custom controls would appear on the last tab of every Office application and that would have its own house—the Add-in Tab. So, when you have Office 2007 open and want to access a specific function written specially for you, you need to look no where except for the Add-in's tab. Isn't that cool enough?
What you will need for this walkthrough: Office 2007 and Visual Studio 2008 (minimum will be the Professional Edition and higher). Make sure that you install all the features, including Visual Studio Tools for Office 3.0.
When you finish your application, it will look like Figure 1. The document loads with the customer names from the "AdventureWorks" database.
Figure 1: The toolbar with your custom application inside the Ribbon.
When you select a particular customer's name from the drop-down list box and click the Show Details button located right below the drop-down list box, the details of purchase made by that customer will appear in the Excel worksheet. The final layout will look like the content of Figure 2.
Figure 2: The desired output after selecting a customer's name and clicking the button.
This brings back memories of what you used to develop earlier with Windows Forms or Web Forms. The user opens up a Windows application, selects a particular combination of data from the toolbar, and views the data in a grid. With the release of VSTO 3, developers can build that feature right into Office 2007 and simplify things when creating custom reports for business organizations. The organization wouldn't need sophisticated network servers or web applications to host their business applications.
Now that you have seen what your custom add-in will look like, it is time to get down to business and write code for this. Fire up Visual Studio 2008 and choose New Project. Select Office 2007 from the Projects tab, and Excel 2007 Add-in from the Templates tab. See Figure 3. Make sure that the .NET Framework 3.5 is selected from drop-down list box at the top. This is one of the new features in Visual Studio 2008 that allows you to target different versions of the .NET Framework.
Figure 3: Select the Excel Add-in from the dialog box.
Now, you need to include the Ribbon Designer to add your functionality. Right-click the project in Solution Explorer and choose New Item. Select Ribbon (Visual Designer) from the pop-up window, as shown in Figure 4.
Figure 4: Select the Ribbon (Visual Designer) from the dialog box.
Give it a name and press Enter. This will open the Ribbon Interface in Design view where you can add your custom controls and so forth, and write code to generate the business logic. In the middle, the Ribbon designer has replaced the custom Windows Form and the tool box now has a separate tab for the Office Controls, as seen in Figure 5. This enables the developer to drag and drop various .NET Controls on the Ribbon designer just like they would do on a Windows or Web form.
Figure 5: The Ribbon designer template opens inside Visual Studio 2008.