我正在创建C#网络服务以将excel文件转换为pdf。当我尝试打开excel文件时,它将引发错误异常。
我尝试在DComConfig
中授予权限以使Application更好,但没有用
Result res = new Result();
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName.Equals("Microsoft Excel (32 bit)")
|| clsProcess.ProcessName.ToUpper().Equals("EXCEL")
|| clsProcess.ProcessName.ToUpper().Equals("EXCEL.EXE"))
{
clsProcess.Kill();
break;
}
}
res.BytesPDF = null;
res.Message = "";
res.Status = false;
res.OutputPath = "";
try
{
var tmpFile = @ConfigurationManager.AppSettings["tempExcelLocation"];
var tmpFileStream = File.OpenWrite(tmpFile);
tmpFileStream.Write(ExcelContent, 0, ExcelContent.Length);
tmpFileStream.Close();
tmpFileStream.Dispose();
foreach (Process clsProcess in Process.GetProcesses())
{
if (clsProcess.ProcessName.Equals("Microsoft Excel (32 bit)")
|| clsProcess.ProcessName.ToUpper().Equals("EXCEL")
|| clsProcess.ProcessName.ToUpper().Equals("EXCEL.EXE"))
clsProcess.Kill();
break;
}
}
Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Interop.Excel.Workbook doc = excel.Workbooks.Open(tmpFile);
错误
Error Exception from HRESULT: 0x800A03EC when executing the last line
我正在使用Microsoft Office2019。