本文介绍了检测已安装的Excel版本(和Service Pack)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够从我正在开发的一些.NET代码中检测我的机器中安装的哪个版本的Excel。我目前正在使用 Application.Version ,但不提供有关Service Pack的信息。

I need to be able to detect which version of Excel I have installed in my machine from some .NET code I'm developing. I'm currently using Application.Version for that, but it doesn't give me information about Service Packs.

我最好指导远离这样的事情:

I would preferably to steer away from something like this:http://www.mvps.org/access/api/api0065.htm

欢迎托管代码

推荐答案

Public Shared Function GetExcelVersion() As Integer
    Dim excel As Object = Nothing
    Dim ver As Integer = 0
    Dim build As Integer
    Try
        excel = CreateObject("Excel.Application")
        ver = excel.Version
        build = excel.Build
    Catch ex As Exception
        'Continue to finally sttmt
    Finally
        Try
            Marshal.ReleaseComObject(excel)
        Catch
        End Try
        GC.Collect()
    End Try
    Return ver
End Function

如果找不到excel,则返回0。

Returns 0 if excel not found.

这篇关于检测已安装的Excel版本(和Service Pack)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 06:38