我正在使用 Microsoft.Office.Interop.Excel
将 Excel 转换为 PDF。但是当我启动 Excel 应用程序时,会出现以下错误。我已经在计算机上安装了 Excel 2013。 (我正在使用 VS2019,Windows 10)。
我的 Excel 位置在 C\Program Files (x86)\Microsoft Office\Office 15\Excel
。
无法加载文件或程序集“office,Version=15.0.0.0,Culture=neutral,PublicKeyToken=xxxxxxxxxxx”。系统找不到指定的文件。
欢迎提出任何建议!
这是我的代码:
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
{
}
}
}
}
Marshal.ReleaseComObject
。 - user585968Dispose()
函数。我只是调用了ExcelApplication = new Application();
。 - Tran B. V. Son