Exporting to Excel Showing (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))

0

am using Microsoft office 2013 office professional. so when am trying to export data from c# to Excel it shows the following error.

The message filter indicated that the application is busy. (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))

but when am using the office 2007 there is no issue with my code. only, the error occur while using office 2013. can any one please provide a suitable solution for this.

The following code am using

                Microsoft.Office.Interop.Excel.Worksheet objWorkSheet1 = null;
                Microsoft.Office.Interop.Excel.Application objExcel = new Microsoft.Office.Interop.Excel.Application
                {
                    Visible = false,
                    DisplayAlerts = false,
                    ScreenUpdating = false
                };
                Microsoft.Office.Interop.Excel.Workbooks objWorkbooks = objExcel.Workbooks;
                Microsoft.Office.Interop.Excel.Workbook objWorkbook = objWorkbooks.Add(Missing.Value);
                Microsoft.Office.Interop.Excel.Sheets objSheets = objWorkbook.Worksheets;
                Microsoft.Office.Interop.Excel.Range objCells;
                Microsoft.Office.Interop.Excel.Range myCell;
                var iCurrentRow = 10;
                var dt = ds;
                int columnsCount = dt.Columns.Count;
                objWorkSheet1 = (Microsoft.Office.Interop.Excel.Worksheet)(objSheets[1]);
                objCells = objWorkSheet1.Cells;
                objWorkSheet1.Cells[2, columnsCount - 1] = ReportCaption;
                objWorkSheet1.Cells[2, columnsCount - 1].Font.Size = 15;
                objWorkSheet1.Range[objWorkSheet1.Cells[5, 2], objWorkSheet1.Cells[5, columnsCount - 1]].Merge();
                objWorkSheet1.Cells[5, 2] = "Printed By: " + Common.Utilities.UserName; ;
                objWorkSheet1.Range[objWorkSheet1.Cells[6, 2], objWorkSheet1.Cells[6, columnsCount - 1]].Merge();
                objWorkSheet1.Cells[6, 2] = "Date: " + DateTime.Now;
                objWorkSheet1.Range[objWorkSheet1.Cells[2, 2], objWorkSheet1.Cells[4, columnsCount - 1]].Merge();
                if (name != null)
                    if (name.Length > 0)
                        objWorkSheet1.Cells[8, 2] = "NAME: " + name;
                objWorkSheet1.get_Range((Microsoft.Office.Interop.Excel.Range)objWorkSheet1.Cells[2, 2], (Microsoft.Office.Interop.Excel.Range)objWorkSheet1.Cells[4, columnsCount - 1]).Cells.HorizontalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;
                objWorkSheet1.get_Range((Microsoft.Office.Interop.Excel.Range)objWorkSheet1.Cells[2, 2], (Microsoft.Office.Interop.Excel.Range)objWorkSheet1.Cells[4, columnsCount - 1]).Cells.VerticalAlignment = Microsoft.Office.Interop.Excel.XlHAlign.xlHAlignCenter;

                for (var h = 0; h < dt.Columns.Count; h++)
                {
                    myCell = (Microsoft.Office.Interop.Excel.Range)objCells[iCurrentRow, h + 1];
                    myCell.Value2 = dt.Columns[h].ColumnName;
                }
                iCurrentRow++;
                for (var r = 0; r < dt.Rows.Count; r++)
                {
                    for (var c = 0; c < dt.Columns.Count; c++)
                    {
                        if (dt.Columns[c].DataType.Name == "String" || dt.Columns[c].DataType.Name == "DateTime")
                        {
                            myCell = (Microsoft.Office.Interop.Excel.Range)objCells[r + iCurrentRow, c + 1];
                            myCell.Value2 = "'" + dt.Rows[r][c].ToString().Trim();
                        }
                        else
                        {
                            myCell = (Microsoft.Office.Interop.Excel.Range)objCells[r + iCurrentRow, c + 1];
                            myCell.Value2 = dt.Rows[r][c];
                        }
                    }
                }
                objWorkSheet1.Cells.EntireRow.AutoFit();
                objWorkSheet1.Cells.EntireColumn.AutoFit();
                objWorkbook.SaveAs(savingFileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal,
                Missing.Value, Missing.Value, Missing.Value, Missing.Value, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive,
                Missing.Value, Missing.Value, Missing.Value,
                Missing.Value, Missing.Value);
                objWorkbook.Close(Missing.Value, Missing.Value, Missing.Value);
                objExcel.Quit();

The following image will come when it close it will not work enter image description here

c#
c#-4.0
export
c#-3.0
export-to-excel
asked on Stack Overflow Feb 12, 2017 by Dona Susan Issac • edited Feb 12, 2017 by Dona Susan Issac

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0