I am trying to import an excel file and working on it with visual studio, c#. When I try to create an excel app so I can use it to read the file I am getting this error upon running the code: "System.IO.FileNotFoundException: 'Could not load file or assembly 'office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c'. The system cannot find the file specified.'" I saw some people that had this problem and said something about excel 2013 but that's not the case here. Anyone has a solution? I'll be more than glad to hear.
Asked
Active
Viewed 386 times
0
-
Check this out: https://stackoverflow.com/questions/32399420/could-not-load-file-or-assembly-office-version-15-0-0-0 You might have the wrong Office installed for 15.0 or no office at all? – Jodn Aug 14 '20 at 16:58
-
I would rather use lightweight library such Npoi or Epplus for that instead of using office. – akd Aug 14 '20 at 17:42
-
@Jodn is there a way to change the office version? Maybe 15.0.0.0 isn't the one I need to use? – itay amit Aug 15 '20 at 13:58
-
@itayamit try to add the COM-Visible reference to office 16.0.x in the Reference Manager->COM in Visual Studio. iirc 15.0 is for Office 2010,2013 and 16. is 2016+ – Jodn Aug 15 '20 at 14:15
-
@itayamit and IMO akd is right. you now develop for office 2016, but on your target machine might have office2013 installed and everything breaks.. go for office DLL independent solution. i'm using https://github.com/ExcelDataReader/ExcelDataReader – Jodn Aug 15 '20 at 14:18
3 Answers
0
you are probably trying to run the app in a PC with no office intalled. Intall this specific version of the office in the PC who will execute the app and try again.

Paulo
- 577
- 3
- 8
- 23
-
I have office installed, that is not the case. Do you mean using a specific version of office? I have the latest one – itay amit Aug 15 '20 at 08:24
0
I actually did what akd said, I used Epplus and it worked very well. Thank you so much for the advise!

itay amit
- 33
- 4
0
1.You could install nuget package Microsoft.Office.Interop.Excel first.
2.It is best for you to set Embed Interop Types to be true.
Configuration: the latest version Microsoft.Office.Interop.Excel, Excel2016
The test code is as follows:
class Program
{
static void Main(string[] args)
{
ReadExcel("D:\\xxx.xlsx");
}
static void ReadExcel(string path)
{
Excel.Application app = new Excel.Application();
Excel.Workbook workbook = app.Workbooks.Open(path);
Excel.Worksheet worksheet = workbook.Worksheets[1];
Excel.Range range = worksheet.UsedRange;
int row = range.Rows.Count;
int column = range.Columns.Count;
for (int i = 1; i < column+1; i++)
{
for (int j = 1; j < row+1; j++)
{
string value = worksheet.Cells[i][j].Text;
Console.WriteLine(value);
}
Console.WriteLine("*********");
}
Console.ReadKey();
}
}
Excel:
Result:

dear_vv
- 2,350
- 1
- 4
- 13