I'm using Microsoft.Office.Interop.Excel
to convert excel to pdf. But when I start Excel application, this error happened. I already installed Excel 2013 on my computer. (I'm using VS2019, Window 10).
My Excel's location is at C\Program Files (x86)\Microsoft Office\Office 15\Excel
.
Could not load file or assembly ‘office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxx’. The system cannot find the file specified
Any suggestions are welcomed!
This is my code:
using Microsoft.Office.Interop.Excel;
using System;
using System.Runtime.InteropServices;
namespace ExcelToPdf
{
public class ExcelApplicationWrapper : IDisposable
{
public Application ExcelApplication { get; }
public ExcelApplicationWrapper()
{
ExcelApplication = new Application(); // start excel application
}
public void Dispose()
{
// Each file I open is locked by the background EXCEL.exe until it is quitted
ExcelApplication.Quit();
Marshal.ReleaseComObject(ExcelApplication);
}
}
}
using System.Collections.Generic;
using System.IO;
using System.Runtime.InteropServices;
namespace ExcelToPdf
{
public class ExcelInteropExcelToPdfConverter
{
public void ConvertToPdf(IEnumerable<string> excelFilesPathToConvert)
{
using (var excelApplication = new ExcelApplicationWrapper()) // got error here
{
}
}
}
}