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:
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