C# Microsoft.Office.Interop.Excel Could not load file Error

Error desc:

Could not load file or assembly ‘office, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c’ or one of its
dependencies. The system cannot find the file specified.

使用Microsoft.Office.Interop.Excel导出到excel文件时碰到的错误,Google了很多,包括dll和更换版本(office、nuget)的解决方法都试过,没有解决,最终对比之前写的项目,解决了问题。

Fixed:
我的项目名为Testing20221031
新建的项目根目录下有个Testing20221031.csproj,下载Microsoft.Office.Interop.Excel的NuGet后打开应该是这样的:



  
    Exe
    netcoreapp3.1
  
  
  
    
    
  


对照之前的项目更改完后是这样:



  
    Exe
    netcoreapp3.1
  

  
    
      tlbimp
      9
      1
      00020813-0000-0000-c000-000000000046
      0
      false
      true
    
  

  
    
  



删了version,加了个ItemGroup,问题解决。

====================================================
附:NPOI是另一个NuGet,另一种导出excel数据的实现方法的库,和Microsoft.Office.Interop.Excel没有关系。

你可能感兴趣的:(C#,C#,Error,excel,c#)