The issue is with Office 2013.
We are hosting excel workbook window in WPF application using HwndHost class. In overridden BuildWindowCore method of HwndHost class, we are creating a MDICLIENT Window and setting this MDICLIENT window handle as parent for Excel main window handle and returning HandleRef object of MDICLIENT window handle from BuildWindowCore method. Once HwndHost control is loaded, we are selecting sheet of excel in the loaded event of HwndHost control. The code for selection of sheet is given below.
dynamic workSheet = this.excelApplication.Workbooks[1].Worksheets[sheetName];
this.excelApplication.Workbooks[1].Activate()
workSheet.Activate();
workSheet.Select(true);
The first time execution of workSheet.Select(true)
halt for few seconds and then it throws exception
“System.Runtime.InteropServices.ComException” with message “The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT))”.
But it executes successfully without delay on subsequent calls. Sometimes the execution halt for minutes on different Systems. This absurd behaviour is seen only once in application instance life time and that too after excel window gets loaded in WPF application. If we execute workSheet.Select(true) before loading of window then it executes properly. Once workSheet.Select(true) executed for first time with exception, it executes successfully without delay on subsequent calls.
Aucun commentaire:
Enregistrer un commentaire