VSTO & .NET & Excel

October 25, 2009

The New Package; Windows 7, VS.NET 2010 and Office 2010

Filed under: .NET & Excel, COM Add-ins, VSTO & Excel — Dennis Wallentin @ 1:55 am

To create a workable structure I have always grouped individual new versions of Windows, VS.NET, VSTO and Office together. The present groups I work with are:

  • Windows XP, VS.NET 2005, VSTO 2005 SE, SharePoint 2003 and Office XP/Office 2003
  • Windows Vista, VS.NET 2008, VSTO 3.0, SharePoint 2007 and Office 2007
  • Windows 7, VS.NET 2010, VSTO 4.0 SharePoint 2010 and Office 2010

The list also reflects my different configuration guest systems on the VMware platform. I have recently replaced Windows Vista 64-bit with Windows 7 64-bit as my host system. The grouping can also be said to represent the optimal situation where we develop solutions with the .NET/VSTO version included targeting the Office version(s) included. At least that is my experience.

While Windows 7 RTM has been released VS.NET 2010 and Office 2010 are still in the beta stage as of this writing. Beta 2 of VS.NET 2010 came out this week while Office 2010 officially still is in beta 1. To complete the picture; Exchange 2010 RTM seems to be around the corner and SharePoint 2010 will soon be in the beta stage.

I have been taking part of the Office beta testing but only for Excel. I have no intention to make any walkthrough about what is new in Excel 2010. It already exist a great number of blogposts and sites that cover all the news in detail like Microsoft Excel Team Blog and Microsoft Office 2010 Engineering

As for the operating system the real successor to Windows XP is Windows 7 and not Windows Vista . The later will probably get the same position as Windows ME already have in all history books. With Windows 7 we get a modern operating system, with more secured network functions, a flexible User Acess Control (UAC) together with a new folder system and improved tools for music and video. Despite all the new “whistle and bells” it is as fast as Windows XP for all kind of operations, including file operations. 

The news in VS.NET 2010 is nearly all about SharePoint developing. VB.NET has also been improved and among other things working with Collection and Array Initializers have been improved and added. As for the other languages I have not been testing anyone of them. The major news in the Beta 2 version is that VSTO 4.0 now is included. At present I’m evaluating VSTO 4.0 so I will get back to it in an upcoming blogpost.

Office 2010 includes news for all the softwares in the suite and will also be better integrated with SharePoint than any previously version. With Office 2010 we also get a new Web based Office suite. My major concern is Excel 2010 desktop version so the other tools as well as the Web based suite are less important to me. Unlike Office 2007 we now can customize the Ribbon UI via a built-in UI and Outlook 2010 has now also fully implemented the Ribbon UI. As a developer I was rather negative surprised when it turned out that we did not get any more events methods in code to control the Ribbon UI with. The Office Button has, together with its content, been revised and improved. The new programming language did not made it to this version so it looks like we will have to wait for Office 15.0.

For Excel 2010 the major news is that we finally have got a 64-bit version of it – Please see the discussion about the 64-bit version here: Excel 2010 – Now With More Bits!. With the 64-bit version it is possible to work with really large datasets which can consume more memory then 4 GB. The future will tell us to which degree we need to develop separated solutions for the 64-bit and 32-bit version of Excel.

Microsoft continues to develop the management of large datasets including data analyse, especially data visualization in Excel. Among the news in Excel 2010 are SparkLines and an improved Pivot Table tool including Slicers. The later allows us to filter data in real-time and when the data is updated so are the Slicers updated. The integration between Excel and SQL Server will in general be handle by the Business Intelligence tool (BI) Microsoft SQL Server PowerPivot for Excel which is an add-in to Excel 2010.

I must honestly say that Microsoft has managed to put the pieces together with the new versions and my overall impression of all the software are positive. Next year will be the year when Microsoft will have a complete updated versions of all the server platforms as well as the other software suites. That is impressive!

Kind regards,
Dennis

September 9, 2009

Goodbye Radio Buttons!

Filed under: .NET & Excel, COM Add-ins, UI Design, VSTO & Excel — Tags: — Dennis Wallentin @ 12:20 pm

For years I have been using the Radio Button control in many of my solutions (where it has been appropriated). When using the control it was usually together with the Group Box control. The following screen shot shows a common approach when using these two controls together and where users are supposed to select one of the three options. Typically one of the Radio Buttons is also pre-checked when the Windows Form is loaded.

RadioButtons

When designing the UI and consider to use Radio Buttons the question we should raise is; when is the number of items relevant to the end users? My answer is when the users are about to make a selection, not before and not after that decision point. After the decision has been made the selected item should be viewed. 

This lead to a new standpoint, at least to me, when designing UI; instead of a group of Radio Button controls we replace them with a Combo Box control as the following screen shot show:

Comboboxes

When the Windows Form is loaded we have the same option as with Radio Buttons; to have one (or more) item(s) selected or to have no no item pre-selected. When the users have made their decisions the selected item is showed in the control. Consequently,  the UI gets cleaner and the Windows form may even be down sized. Of course, the same discussion can be applied to the List Box control.

All in all, for all my future projects I will simple drop the Radion Button control and instead use the Combo Box control. Do You agree?

Kind regards,
Dennis

September 2, 2009

Microsoft Chart Control for .NET

Filed under: .NET & Excel, Charts components, VSTO & Excel — Dennis Wallentin @ 10:39 am

In 2007 Microsoft aquired Dundas Data Visualization but Dundas still remains as a standalone company. What matters is that by acquiring Dundas Microsoft got access to all the Dundas .NET controls. Last year Microsoft made the Chart control available for free. Originally the Chart control comes from Dundas but  Microsoft has done an update of its code base so it fits better with Visual Studio.

So far Microsoft have only provided some basic controls in Visual Studio and has let other providers to provide more advanced commercial controls. But with the Chart control they make an exception and provide an excellent control for free. Perhaps we will see more of that in the future?

I find the Chart control to be a great companion into my solutions where it requires some data presentation in terms of charts. Due to this I believe it deserves to be more highlighted within the Excel and .NET developing communities.

 Initially I planned to create a sample and discuss it in more detail however because MSFT has made over 200 samples available there are no reasons why I just should repeat some of these samples here. Actually, the sample collection is very nice and all the code samples can be viewed in both C# and VB.NET as the below screen shot shows.

Samples

What should be noted is that we cannot place the control on worksheets when creating document centric VSTO solutions. But on the other hand we don’t need to use it like that as we have access to Excel’s nice built-in chart control.

 For more information and to download please see the following links:

A great blog about the Chart control is Alex Gorev’s Weblog.

Kind regards,
Dennis

August 15, 2009

Check which Windows version is running

Filed under: .NET & Excel, VSTO & Excel — Dennis Wallentin @ 12:51 pm

In the second edition of PED we introduce a new area; Creating Cross Version Applications. That is, to develop solutions that must run with all Excel versions and Windows versions using a single code base. I will not discuss how to code against different Excel versions. Instead I set focus on running .NET solutions on different Windows versions, i.e. Windows 2000/Windows XP and Windows Vista/Windows 7.  It should be noted that I have previously blogged how to check which Excel version that is installed.

With Windows 2000 and Windows XP we know that the user accounts are available in paths like:
C:\Documents and Settings\Dennis

In Windows Vista and Windows 7 the user accounts are located in  paths like:
C:\Users\Dennis

Given this information we can rather easily code for different Windows versions in VB.NET. First we need to find out which Windows version that the targeting computers use. As the code shows below the namespace My.Computer once again comes to our rescue.

In the next step we retrieve the current user’s identity which is carried out by the SystemInformation namespace. Finally we put it together with the help from the StringBuilder namespace.

Code Windows Version and current user 1

When we run the code on a Windows Vista configuration we get the following information: 

Output when running on Windows Vista

When the User Access Control (UAC) is turned on (Windows Vista/Windows 7) we cannot access the c:\ root unless we run as administrator. But no matter the UAC status we can always access the current user’s folder system. In that way we can write and read files to the user’s folders in addition to the above.

Kind regards,
Dennis

August 4, 2009

Connected to the network?

Filed under: .NET & Excel, COM Add-ins, VSTO & Excel — Dennis Wallentin @ 1:37 am

It has been a while since I last made a post here.  But I intend to get up to speed and publish on a more regular basis. Anyway, on the .NET platform and with VB.NET we can rather easy check if the computer we work on is connected to a network or not.

To know that information allows us:

  • To run methods that update workbooks with the latest data.
  • Run network located templates and individual workbooks.
  • Load network based add-ins.

Technically we will be using the My namespace to find out if the computer is connected or not.  More specifically we will use the  My.Computer namespace which provides methods to control the computer’s hardware and the system software.  Among other things, it allows us to work with the file system, clipboard, Windows Registry network printers, network connection and keyboard & mouse.

The following snippet code shows how we can use it to determine if the computer is connected to a network.

Network

 

Because the property isAvailable only indicates if there is a network available or not we need to make sure that there is a connection to the network we actually want to access. In order to do so we use the Ping function to insure that the wanted remote location is available.

Kind regards,
Dennis

June 4, 2009

Implement the Ribbon UI in Windows Forms

Filed under: .NET & Excel, .NET SQL Tester, VSTO & Excel — Dennis Wallentin @ 6:45 pm

Some of us Excel developers like the Ribbon UI while others find it more difficult to work with it. No matter what we developers think about it exist a growing number of clients requiring that the Ribbon UI to be implemented in .NET based Excel solutions.

Microsoft offers no controls that can be used to implement any Ribbon UI solution so we are forced to decide which third-party controls package to be used.  Of cause, most large vendors, such as Component One et al, offer components that can be used but they can be rather expensive.  DotNetBar from DevComponents is an inexpensive controls package including controls for the Ribbon UI.  I have been using the package for a while in clients solutions. DotNetBar includes 47 controls whereof some controls allow us to create a Ribbon UI in Windows Forms. All controls that are shipped with DotNetBar are highly customized. The controls are also frequently updated and new versions of DotNetBar are released on a regular basis.

With the package a collection of relevant case studies are shipped, both in VB and in C#. A knowledgebase is available to the DotNetBar customers and I find it easy to use it and it also provides relevant links based on the search criterias. The knowledgebase can also be accessed via the help file. The help file describes, in a strictly technical way, the DotNetBat assembly and its namespaces.

The following screen shot shows DotNetBar Samples Explorer: 

DotNetBar4

Because I find the controls to be good, especially the Ribbon UI controls, I have decided to use them for the upcoming .NET version of my commercial tool for Excel, the SQL Tester. The following screen shots are from the alpha version of SQL Tester.NET and all controls in use are part of DotNetBar package. 

The following screen shot views the main Windows Forms for SQL Tester.NET in the VS IDE. In addition to use a Ribbon UI it also use a tabcontrol with two tabs. These tabs will be synchronized with the tabs in the Ribbon UI and therefore is hidden when the tool is being executed.

DotNetBar1

Next screen shot shows the code in use to synchronize the tabs in the tab control with the tabs in the Ribbon control:

CodeDotNetBar

Having access to a tab’s click event is something we miss when building native Ribbon UI solutions in Excel. With DotNetBar we have it available without the need to create any workaround. Initially it may take some time to get used to the controls and what they offer. In my experience I would like to say that the more time we put into learning the controls the more we can leverage them in our Windows Forms solutions.

The following two screen shots show when SQL Tester.NET is being executed and we switch between the tabs in the Ribbon UI solution.

DotNetBar2

DotNetBar3

Kind regards,
Dennis

May 5, 2009

Sheet Navigation in The Ribbon UI – Part II

Filed under: .NET & Excel, VSTO & Excel — Dennis Wallentin @ 11:40 pm

In my first post about Sheet Navigation I showed a basic approach. Here I will show a more practical and realistic solution to navigate between sheets. The example is based on a VSTO workbook however it can be applied to both native Excel solutions as well as managed COM/VSTO add-ins.

When it comes to customize the Ribbon UI with VBA and with VB.NET the major difference is the callbacks signatures. Because I constantly forget which signatures to be used depending on which language I use I check with the following article: Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3).

Anyway, in this example I use the dropDown control but the drawback with it is that it does not explicitly give us the name of the selected item, only its ID and index number. Therefore we need to resolve it in the code. 

Although we should strive to create fully dynamic applications, they come with the price of having to write code for all possible scenarios. In real-world applications we therefore tend to create semifixed applications where some parts of the solutions are fixed and some parts are dynamic. In the example here we have a fixed list of sheets whose names will not change during runtime and we therefore do not need to invalidate the dropDown control during runtime. On the other hand, we will not hard-code the sheets names in order to ease the maintenance.

The following screen shot shows the whole VSTO project: 

project-sheetnavigation

As we can see we have four worksheets and one chart. One of the worksheets, “Hidden”, is hidden which we also need to resolve in the code.

The following screen shot lists the Ribbon UI XML solution:

ribboncustom-sheetnavigation

The next screen shot shows the relevant code in the ThisWorkbook module:

code-thisworkbook-sheetnavigation

We grab the collection of sheets in the workbook in a sheet collection variable which we use in the callbacks signatures as the following screen shot shows:

code-ribbonui-sheetnavigation

It should be noted that I use Option Strict for the example solution, i.e. it forces us to cast.  When running it we can navigate between the sheets rather smooth as the following screen shot lists:

running-the-sheet-navigation

The example shows that we can rather easily create robust solutions to navigate between the sheets in a workbook. Compared with the basic approach the above solution gives the end users a better option as it shows the names of the sheets.

In the coming blogpost I will demonstrate how we can implement the Ribbon UI in Windows Forms.

Kind regards,
Dennis

April 10, 2009

Sheet Navigation in The Ribbon UI – Part I

Filed under: .NET & Excel, VSTO & Excel — Dennis Wallentin @ 11:25 am

This is the first post out of two that will be dealing with Sheet Navigation and how we create solutions for it in the Ribbon UI. In my experience sheet navigation is common for large-scale dictator applications but also for smaller application solutions.

The example provided here is based on a VSTO workbook solution which contains five worksheets and the whole solution is showed in the following screen shot:

vsto-workbook-solution

The end user UI is based on four customized images and when the users run the solution the following UI is available:

vsto-workbook-ui

The customized Ribbon UI solution is a basic approach that does not involve any advanced or complext coding. The following procedure is executed when users click on one of the image buttons:

code-vsto-workbook-solution

As we can see we convert the ActiveSheet to an Interop worksheet which gives us access to the Previous and Next methods of the worksheet object. Other then that standard code is being use and should not create any issuse.

In the second post I will discuss more advanced sheet navigation in the Ribbon UI.

Kind regards,
Dennis

March 11, 2009

Sharing Custom Tabs in The Ribbon UI

Filed under: .NET & Excel, VSTO & Excel — Dennis Wallentin @ 11:58 pm

To let add-ins (native, unmanaged/managed COM add-ins and VSTO add-ins) share tabs is a good strategy but it can be applied in two different ways. Which to apply is depended on the individual add-ins.

Sharing the Add-ins Tab
For small application it is not necessary to use tabs on their own. Instead we can share the Add-in tab with other add-ins as the first screen shot shows:

tabaddins

 In this case we use the following customized Ribbon XML:

tabaddinsribbonxml

It should be noted that it is not required that any classic CommandBar add-in is activated to access the built-in tab Add-ins. 

Sharing Custom Tabs
For large-scale applications it may be an advantage to split the applications in smaller parts and let the parts share a custom tab. To get there it requires that we:

1. Use a unique identical namespace and 
2. Use a unique identical idQ attribute in the add-ins’ customized Ribbon XML.

A result of this is showed in the following screen shot:

sharedtab

To produce this output we use the following customized Ribbon XML in the add-ins.

The first add-in’s customized Ribbon XML:

 firstcustomizedribbonxml

The second add-in’s customized Ribbon XML:

secondcustomizedribbonxml

As we can see they share the same namespace and call the same idQ attribute which makes it possible to let add-ins share a custom tab.

The customized Ribbon XML for sharing the custom tab is available here.

Kind regards,
Dennis

March 2, 2009

Using Custom Images in Ribbon UI Solutions

Filed under: .NET & Excel, VSTO & Excel — Dennis Wallentin @ 5:10 pm

Although the number of built-in images in Excel is large we still may want to use custom images. Because it exist a great number of inexpensive commercial images packages it is not justified to spend our time to create customized images.

So the question is which image format to use? The Ribbon drawing engine is designed to work best with full-color (24-bit) images that also have an alpha channel to control each pixel’s transparency. Since the PNG file format supports an alpha channel and produces relatively small files, it is the best alternative. The preferred sizes of custom images are either 16×16 (small size) or 32×32 (large size).

The first step is to add the selected images to a project’s resources and then create the code to use them. Adding images to the resources is not an issue and the first figure shows the added images for the case.resources1

 

The next screen shot shows the content of the Ribbon.xml file which is also added to the resources of the project:

ribbonxml

The following screen shot shows the class Ribbon.vb:

ribbonclass

The key to the solution is the function GetImage which uses the System.Drawing namespace to return Bitmap objects.

The next screen shot shows ThisAddin class of the VSTO Add-in I use for the case:

thisaddin

 

When running the above code the customized Ribbon UI solutions looks like the following:

running

Looking on the solution it reveals nothing extraordinary in order to use custom images in Ribbon UI solutions.  

Kind regards,
Dennis

(If we only have access to images in the GIF or BMP or JPEG file format then we can apply the same approach as with the PNG images.)

Older Posts »

Blog at WordPress.com.