Section 5.11.Distribute .NET Applications That Use Excel


5.11. Distribute .NET Applications That Use Excel

Use the Visual Studio .NET Setup and Deployment project to create an installation program for applications that use Excel as a component. (See "Distribute .NET Components" for a walk-through of using the Setup Wizard.)

5.11.1. How to do it

The .NET setup tools detect the .NET Frameworks and Excel PIAs as dependencies of any application that uses Excel as a component and includes those files with the installation. However, the setup tools do not automatically check for the installation of Microsoft Excel or any other Microsoft Office product.

To verify that Excel is installed before installing your .NET application, add a launch condition to your installation project. To do this, create an installation project in Visual Studio .NET and follow these steps:

  1. Select the installation project, then click the Launch Conditions Editor in the Solutions Explorer (Figure 5-12).

    Figure 5-12. Adding a launch condition to an installation project


  2. In the Launch Condition window, right-click Search the Target Machine and select Add File Search. Visual Studio .NET creates a file search item and displays its properties (Figure 5-13).

    Figure 5-13. Setting the File Search properties to find Excel 2003


  3. Set the FileName, Folder, and MinVersion properties, as shown in Figure 5-13.

If your application uses Excel 2003, you should exclude the Office PIAs from the automatically detected dependencies in your installation project. According to Microsoft, you should not distribute the Office 2003 PIAs as part of your application. Those files are a part of the Office System. If you include the PIAs as part of your installation, you could violate the user's license and uninstalling your application could remove the PIAs breaking Office features. Instead, you should use the Office 2003 Setup to install the PIAs.

To exclude the Office 2003 PIAs from your installation project, select the dependency in the Solution Explorer and set its Exclude property to True (Figure 5-14).

Figure 5-14. For Excel 2003, exclude the Office PIAs


There are PIAs available for both Excel XP and Excel 2003. According to Microsoft, it is OK to distribute the Excel XP PIAs with your application, since they aren't considered part of the Office XP system.

You can also use Visual Studio .NET type library import tools to create interop assemblies for earlier versions of Excel (they won't work as well as the PIAs, but they will work). All interop assemblies are tied to a specific version of Excel, so you should check that the required version of Excel is installed on the user's computer before installing your application and each time your application starts. You can use the following code to detect which version of Excel is installed:

    ' Uses the following Imports statement for RegistryKey classes:    Imports Microsoft.Win32    Function GetExcelVer(  ) As String        ' Define the RegistryKey objects.        Dim regRoot As RegistryKey, regExcel As RegistryKey, ver As String        ' Get root registry entry.        regRoot = Microsoft.Win32.Registry.ClassesRoot        ' Get the Excel current version registry entry.        regExcel = regRoot.OpenSubKey("Excel.Application\CurVer")        ' If regExcel is Nothing, then Excel is not installed.        If IsNothing(regExcel) Then            ' Close Registry key.            regExcel.Close(  )            ' Return 0, no version is installed            ver = "0"        Else            ver = regExcel.GetValue("")        End If        ' Close registry.        regExcel.Close(  )        ' Return the Excel version.        Return ver    End Function

It is theoretically possible to have a .NET application work with multiple versions of Excel, however you would have to install interop assemblies for each version, restrict the features you use based on the version of Excel that is installed, and expend considerable effort debugging and testing your application for each Excel version.

5.11.2. What about...

To learn how toLook here
Create interop assemblies for earlier versions of OfficeSearch Visual Studio .NET Help to find the topic "Importing a Type Library as an Assembly"
Use the Launch Condition editorSearch Visual Studio .NET Help Index for "Launch conditions"




    Excel 2003 Programming. A Developer's Notebook
    Excel 2003 Programming: A Developers Notebook (Developers Notebook)
    ISBN: 0596007671
    EAN: 2147483647
    Year: 2004
    Pages: 133
    Authors: Jeff Webb

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net