I'm creating a C# webservice to convert excel file to pdf. When I attempt to open the excel file it throws an error exception.

I've tried to give permissions in DComConfig to excel Application, but didn't work

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

Error Exception from HRESULT: 0x800A03EC when executing the last line 

I'm using Microsoft Office 2019.

0 Answers