我正在创建用于内部部署的wpf应用程序。
使用该软件的用户在尝试创建excel互操作实例时遇到以下错误。
Retrieving the COM class factory for component with CLSID (...) failed due to the following error: 80070002 The system cannot find the file specified
捕获错误的部分如下
try
{
_excelApplication = new microsoft.Office.Interop.Excel.Application();
GetWindowThreadProcessId(_excelApplication.Hwnd,out ExcelAppProcessId);
_excelApplication.ScreenUpdating = false;
}
catch(Exception e)
{
//TODO Move message box to parents
MessageBox.Show($"Termination Error: Could not open Excel Application: {e.Message}");
Environment.Exit(110);
}
以前,同一用户在尝试打开access时遇到问题(不记得确切的错误是什么),我实现了以下解决方案。
try
{
//MessageBox.Show($"OS: {EnvironmentFunctions.is64BitOperatingSystem} Process: {EnvironmentFunctions.is64BitProcess}");
if (EnvironmentFunctions.is64BitOperatingSystem && !EnvironmentFunctions.is64BitProcess)
{
string PathValue = "";
string sAdd = "";
string strCommonFiles =
Environment.GetEnvironmentVariable("CommonProgramFiles(x86)");
sAdd = ";" + strCommonFiles + "\\microsoft shared\\DAO";
PathValue = Environment.GetEnvironmentVariable("Path");
PathValue += sAdd;
Environment.SetEnvironmentVariable("path",PathValue);
}
_accessApplication = new microsoft.Office.Interop.access.Application();
GetWindowThreadProcessId(_accessApplication.hWndaccessApp(),out accessAppProcessId);
}
catch
{
MessageBox.Show("Termination Error: Could not open access Application");
Environment.Exit(110);
}
是否有类似的解决方案,但适用于Excel互操作?
关于用户的注释:它们是少数几个正在运行的Windows 7之一。