检查 电脑上装的access版本

zlb789 zlb789 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

Type type;
object access = null;
object version = null;

type = Type.GetTypeFromProgID("Access.Application");//Access 判断出错 excel可以

if (type == null)
{
MessageBox.Show("没有安装access"); Application.Exit();
}
else
{
access = Activator.CreateInstance(type);
if (access == null)
{
MessageBox.Show("没有安装access");
Application.Exit();
}
else
{
version = type.GetProperty("Version").GetValue(access, null);
PropertyInfo p = type.GetProperty("Visible");
p.SetValue(access, true, null);//设置可见性
MethodInfo[] ms=type.GetMethods();//CloseCurrentDatabase 退出数据库
type.GetMethod("Quit").Invoke(access, null);//type.GetProperty("Visible").ReflectedType
}
}
if (version != null)
{
// MessageBox.Show("Excel版本号是:" + version.ToString());
}


上面如果是判断excel 可以 ,但是如果是access 就出在调用quit 或者CloseCurrentDatabase 方法的时候出错。

怎么解决
...全文

相关推荐

评论 15
收藏 已收藏
分享
返回顶部
zlb789
C# 111,128 成员 642,536 内容