HRESULT的异常:0x800A03EC-Office Excel

时间:2019-05-03 11:32:08

标签: c# excel web-services exception interop

我正在创建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。

0 个答案:

没有答案