Click here to Skip to main content
15,911,531 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys,

Could you please help me resolve the error as below:

The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))

This exception is thrown when we call Show() method from xlDialogPrintPreview of excel via C# code. See my codes:

C#
excelApp = new Microsoft.Office.Interop.Excel.Application();

                           excelApp.DisplayAlerts = false;
                           excelApp.OnKey("^c";, string.Empty);
                           excelApp.OnKey("^v";, string.Empty);
                           excelApp.OnKey("^s";, string.Empty);
                           excelApp.Interactive = false;

                           wb = excelApp.Workbooks.Open("abc.xlsx";, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                               Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

                           excelApp.Visible = true;

                          
                           try
                           {
                               ws = (Microsoft.Office.Interop.Excel.Worksheet)wb.ActiveSheet;                             
                             
                  excelApp.Dialogs[Microsoft.Office.Interop.Excel.XlBuiltInDialog.xlDialogPrintPreview].Show(
                                               Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                               Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                               Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                               Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                               Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                               Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

                               GC.Collect();
                               GC.WaitForPendingFinalizers();
                               Marshal.FinalReleaseComObject(ws);
                               wb.Close();
                               Marshal.FinalReleaseComObject(wb);

                               excelApp.Quit();
                               Marshal.FinalReleaseComObject(excelApp);
                              
                           }
                           catch (Exception ex)
                           {
                               MessageBox.Show(ex.StackTrace);
                               wb.Close();
                               excelApp.Quit();
                              
                           }



Thanks,
Trong
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900