无法加载文件或程序集的Microsoft.Office.Interop。Excel,Version = 15.0.0.0、文化=中立,都71 e9bce111e9429c

时间:2022-06-03 03:15:12

I'm trying to publish web site on IIS at Windows Server 2008 R2. my web site has a feature which download an excel file to apply some edits then upload it again. When access the excel file to be downloaded I got this error: "Could not load file or assembly 'Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' or one of its dependencies. The system cannot find the file specified."

我想在Windows Server 2008 R2上发布IIS上的网站。我的网站有一个功能,它下载一个excel文件来应用一些编辑,然后再上传。当访问要下载的excel文件时,我得到了这样一个错误:“无法加载文件或程序集的Microsoft.Office.Interop。”Excel, Version=15.0.0.0, Culture=中性,PublicKeyToken=71e9bce111e9429c'或它的一个依赖项。系统无法找到指定的文件。

Code which get File:

代码文件:

clsExcel = new ApplicationClass();
    clsExcel.Visible = false;
    clsWorkbook = clsExcel.Workbooks.Open(Server.MapPath("/file path ... "), 2, false, 5, "", "", true, XlPlatform.xlWindows, "", false, true, 0, false, true, XlCorruptLoad.xlNormalLoad);
    // get worksheet 4 ...
    clsWorksheet = (Worksheet)clsWorkbook.Worksheets[4];
    clsWorksheet.get_Range("A2", "D1000").EntireRow.Delete();
     clsWorkbook.Save();
        clsWorkbook.Close(false, "", false);
        // release...
        clsExcel.Quit();

I'm sure that my code is well, because I'm running it on my personal PC which has Windows 10 OS with Office 2013 and it works perfectly. I think I miss some configuration or file which must be exist at the server.

我确信我的代码很好,因为我在我的个人电脑上运行它,它有Windows 10操作系统和Office 2013,并且运行得很好。我想我错过了一些必须存在于服务器上的配置或文件。

After Days of search I found a lot of solutions but it is not working with me like: - Install Office 2010 - Customize Microsoft Excel Application in DCOM Config to allow access for IIS_User and NETWORK SERVICE - Add Microsoft.Office.Interop.Excel as a reference - Comment assembly line from web.config

经过几天的搜索,我找到了很多解决方案,但是它并没有像:-安装Office 2010 -在DCOM配置中定制Microsoft Excel应用程序以允许IIS_User和网络服务的访问——添加Microsoft.Office.Interop。Excel作为来自web.config的引用注释装配线

What should I do?

我应该做什么?

Thanks in advance

谢谢提前

3 个解决方案

#1


2  

If you are not going to install Office 2013 on your web server then you will need to copy the libraries when you publish your web site. In your Visual Studio project you will need to set Copy Local to True for the Interop assemblies. That way when you publish your site the referenced libraries will be copied along with your site and referenced from the copied files.

如果您不打算在web服务器上安装Office 2013,那么在发布web站点时需要复制库。在Visual Studio项目中,您需要为Interop程序集将Copy Local设置为True。这样,当您发布站点时,引用的库将与站点一起被复制,并从复制的文件中被引用。

Something else you might need to check is that Enable 32-bit Applications is set to True in your app pool.

您可能需要检查的另一件事是,在应用程序池中,Enable 32位应用程序被设置为True。

#2


0  

Another way I found and after trying it it solved:

我找到了另一种方法,试了一下就解决了:

  1. Install Office 2010 on your local PC.
  2. 在本地PC上安装Office 2010。
  3. Add reference to your project from visual studio > COM > Microsoft office 14.0 Object Libaray.
  4. 从visual studio > COM > Microsoft office 14.0对象Libaray中添加对您的项目的引用。
  5. Build and Publish web site.
  6. 建立和发布网站。
  7. Replace the old published folder with
    the new one.
  8. 用新文件夹替换已发布的旧文件夹。
  9. Make sure that your server has the same office version "2010" you installed on local PC.
  10. 确保您的服务器上安装了与本地PC上相同的office版本“2010”。
  11. Finally, it works
  12. 最后,它的工作原理

#3


0  

1: Install Microsoft Office in Client Machine 2: Check Microsoft.Interop.Office.Excel for Error Version in present in your bin directory or not .

1:在客户端机器上安装Microsoft Office 2:检查Microsoft.Interop.Office。Excel中显示的bin目录中的错误版本。

#1


2  

If you are not going to install Office 2013 on your web server then you will need to copy the libraries when you publish your web site. In your Visual Studio project you will need to set Copy Local to True for the Interop assemblies. That way when you publish your site the referenced libraries will be copied along with your site and referenced from the copied files.

如果您不打算在web服务器上安装Office 2013,那么在发布web站点时需要复制库。在Visual Studio项目中,您需要为Interop程序集将Copy Local设置为True。这样,当您发布站点时,引用的库将与站点一起被复制,并从复制的文件中被引用。

Something else you might need to check is that Enable 32-bit Applications is set to True in your app pool.

您可能需要检查的另一件事是,在应用程序池中,Enable 32位应用程序被设置为True。

#2


0  

Another way I found and after trying it it solved:

我找到了另一种方法,试了一下就解决了:

  1. Install Office 2010 on your local PC.
  2. 在本地PC上安装Office 2010。
  3. Add reference to your project from visual studio > COM > Microsoft office 14.0 Object Libaray.
  4. 从visual studio > COM > Microsoft office 14.0对象Libaray中添加对您的项目的引用。
  5. Build and Publish web site.
  6. 建立和发布网站。
  7. Replace the old published folder with
    the new one.
  8. 用新文件夹替换已发布的旧文件夹。
  9. Make sure that your server has the same office version "2010" you installed on local PC.
  10. 确保您的服务器上安装了与本地PC上相同的office版本“2010”。
  11. Finally, it works
  12. 最后,它的工作原理

#3


0  

1: Install Microsoft Office in Client Machine 2: Check Microsoft.Interop.Office.Excel for Error Version in present in your bin directory or not .

1:在客户端机器上安装Microsoft Office 2:检查Microsoft.Interop.Office。Excel中显示的bin目录中的错误版本。