The remote procedure call failed. (Exception from HRESULT: 0x800706BE) in Windows Server 2016 and Office 365

0

I have a C# application in server 2016. It was running fine before installing Office 365.

We recently installed Office 365 in the server. Application is failing with an exception

"The remote procedure call failed. (Exception from HRESULT: 0x800706BE) at Microsoft.Office.Interop.Excel.Workbooks.OpenText(String Filename, Object Origin, Object StartRow, Object DataType, XlTextQualifier TextQualifier, Object ConsecutiveDelimiter, Object Tab, Object Semicolon, Object Comma, Object Space, Object Other, Object OtherChar, Object FieldInfo, Object TextVisualLayout, Object DecimalSeparator, Object ThousandsSeparator, Object TrailingMinusNumbers, Object Local).

I have code like below to generate the XLS file...

object[,] myArray = {{1, 1}, {2, 1}, {3, 1}, {4, 1}, {5, 1}, {6, 1}
                    , {7, 1}, {8, 1},{9, 1},{10, 1},{11, 1},{12, 1},{13, 1},{14, 1},{15, 1},{16, 1},{17, 1},{18, 1},{19, 1}};
        Excel.Application excelApp = new Excel.Application();
        excelApp.Visible = true;
        Excel.Workbooks newWorkBooks = excelApp.Workbooks;
        Excel.Workbook m_wB;
        object m_objOpt = System.Reflection.Missing.Value;
        newWorkBooks.OpenText(textFilePath, 437, 1, Excel.XlTextParsingType.xlDelimited, Excel.XlTextQualifier.xlTextQualifierDoubleQuote,
           false, false, false, false, false, true, "|", FieldInfo: myArray);
        m_wB = excelApp.ActiveWorkbook;

        Excel.Worksheet workSheet = (Excel.Worksheet)m_wB.Worksheets.get_Item(1);

        string[] getFiles = Directory.GetFiles(Directory.GetParent(outputPath).ToString(), sheetName + "_*.txt");

        FormatSheet(workSheet, excelApp, sheetName, (getFiles.Length == 0));


        m_wB.SaveAs(outputPath, Excel.XlFileFormat.xlWorkbookNormal, m_objOpt, m_objOpt, m_objOpt, m_objOpt,
            Excel.XlSaveAsAccessMode.xlNoChange, m_objOpt, m_objOpt,
             m_objOpt, m_objOpt);
        m_wB.Close(false, m_objOpt, m_objOpt);
        newWorkBooks.Close();
        excelApp.Quit();

It is failing at OpenTextFile().

Any suggestions...

microsoft-excel
microsoft-office
asked on Super User Apr 20, 2020 by KPK • edited Apr 20, 2020 by Scott Craner

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0