|
5.11. Distribute .NET Applications That Use ExcelUse 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 itThe .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:
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 PIAsThere 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...
|
|