我在服务器 2016 中有一个 C# 应用程序。在安装 Office 365 之前,它运行良好。
我们最近在服务器上安装了 Office 365。应用程序出现异常
“远程过程调用失败。(来自 HRESULT 的异常:0x800706BE)位于 Microsoft.Office.Interop.Excel.Workbooks.OpenText(字符串文件名、对象来源、对象 StartRow、对象数据类型、XlTextQualifier TextQualifier、对象 ConsecutiveDelimiter、对象制表符、对象分号、对象逗号、对象空间、对象其他、对象 OtherChar、对象 FieldInfo、对象 TextVisualLayout、对象 DecimalSeparator、对象 ThousandsSeparator、对象 TrailingMinusNumbers、对象本地)。
我有如下代码来生成 XLS 文件...
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();
它失败了OpenTextFile()
。
有什么建议...