Microsoft.Office.Interop.Excel.Application-调用不同版本的Excel [英] Microsoft.Office.Interop.Excel.Application - Invokeing Different Versions of Excel

查看:856
本文介绍了Microsoft.Office.Interop.Excel.Application-调用不同版本的Excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下问题:

var oExcelApp = new Microsoft.Office.Interop.Excel.Application();

在这台计算机上,这将启动Excel 2016,但是我的计算机上同时安装了Excel 2010和Excel 2016.我想改用2010年启动,然后在我的计算机上同时安装2010年和2016年.

On this machine this starts Excel 2016, however I have both Excel 2010 and Excel 2016 installed on my machine. I'd like to start 2010 instead, and I'd like to keep both 2010 and 2016 installed on my machine when I do that.

根据以编程方式使用遵循命令 >:

According to this post, it's not possible. However, my understanding is that you can do this programmatically using the following commands:

(要将Excel 2010注册为默认应用程序)

"C:\Program Files (x86)\Microsoft Office\Office14\Excel.exe" /regserver

但是,当我运行此命令时,它所做的只是打开excel,未观察到所需的效果.是否可以通过某种注册表更改来做到这一点?还是引用不同的库版本?

However when I run this command, all it does is open excel, the desired effect is not observed. Is there a way to do this, maybe with some sort of registry change? Or referencing a different version of libraries?

我也尝试过:

var oExcelApp = (Microsoft.Office.Interop.Excel.Application)Activator.CreateInstance(Type.GetTypeFromProgID("Excel.Application.14"));

似乎也不管用,无视excel版本并运行2016,无论指定版本.

Doesn't seems to work either, disregards the excel version and runs 2016 irregardless of the specified version.

推荐答案

看起来效果很好.不确定"_Application"和"Application"之间的区别是什么,但建议使用注释"Application":

This seems to work quite well. Not sure what the difference between "_Application" and "Application" is, but per the comment "Application" is preferred:

string pathToTheVersionOfExcel "...";
int amountOfTimeToWaitForFailure = 5000;

Process process = new Process();
process.StartInfo.FileName = pathToTheVersionOfExcel;
process.Start();

Thread.Sleep(amountOfTimeToWaitForFailure);

oExcelApp = (Application)Marshal.GetActiveObject("Excel.Application");

这篇关于Microsoft.Office.Interop.Excel.Application-调用不同版本的Excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆