【問題描述】
在 UiPath (2019.3.0 Community Edition) 使用 Excel Application Scope + Read Cell 讀取 Exce l時報錯
這個問題從 4/8/2019 17:47 起,到今天 4/15/2019 17:06,困擾了我一周,終於解決了!
下圖是 Designer panel 的 workflow 和 異常截圖
以下是詳細的報錯信息:
19.3.0+Branch.master.Sha.5fdb43627d7d3c011018bb545ddf9470210d44a9 Source: Excel Application Scope Message: Error opening workbook. Make sure Excel is installed. Exception Type: System.Exception An ExceptionDetail, likely created by IncludeExceptionDetailInFaults=true, whose value is: System.Exception: Error opening workbook. Make sure Excel is installed. ----> System.InvalidCastException: Unable to cast COM object of type 'Microsoft.Office.Interop.Excel.ApplicationClass' to interface type 'Microsoft.Office.Interop.Excel._Application'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155). at System.StubHelpers.StubHelpers.GetCOMIPFromRCW(Object objSrc, IntPtr pCPCMD, IntPtr& ppTarget, Boolean& pfNeedsRelease) at Microsoft.Office.Interop.Excel.ApplicationClass.set_SheetsInNewWorkbook(Int32 RHS) at UiPath.Excel.WorkbookApplication.StartNewApplication() --- End of inner ExceptionDetail stack trace --- at UiPath.Excel.WorkbookApplication.StartNewApplication() at UiPath.Excel.WorkbookApplication.InitializeExcelApp() at UiPath.Excel.Activities.ExcelApplicationScope.<>c.<.ctor>b__44_0(WorkbookArguments args) at UiPath.Excel.Activities.ExcelApplicationScope.Execute(NativeActivityContext context) at System.Activities.NativeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.ActivityInstance.Execute(ActivityExecutor executor, BookmarkManager bookmarkManager) at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)
問題關鍵點:
This operation failed because the QueryInterface call on the COM component for the interface with IID '{000208D5-0000-0000-C000-000000000046}' failed due to the following error: Interface not registered (Exception from HRESULT: 0x80040155).
【解決方法】
可能的原因(不太確定):
之前電腦里安裝了一個 32位的 Visio,但是安裝的 office 365 是 64位的,引起注冊表沖突
嘗試過,但不好用的解決方法:
- 刪除32位的 Visio,然后在Programs and Features - Office 365 - Change (聯網) 修復 Office 365,重啟
最終解決方法,請依次操作下方鏈接的內容:
0x80040155 - Interface not Registered
Ensure MSOUTL.LIB is Registered (regtlibv12.exe "C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE")
p.s 上邊文章中出現的 {00062FFF-0000-0000-C000-000000000046} 是 Outlook 的,如果你和我一樣遇到的是 Excel 的問題,只需要將其換成 {00020813-0000-0000-C000-000000000046} 即可
【曲線救國的方法】
Excel Application Scope + Read Cell 的搭配是需要安裝 Excel 軟件的(當然啦,上邊的 Issue 就是在安裝了Excel的情況下還是出現問題了),如果嫌解決起來太麻煩,還有另外一個曲線救國的方法,就是使用不需要安裝 Excel 的 Read Cell 的 activity (這個方法無論如何都不會報錯),請注意,雖然這兩個方法都叫 Read Cell,但所屬的包是不一樣
- 在 Excel Application Scope + Read Cell (UiPath.Excel.Activities.ExcelReadCell) 中,excel 的路徑path 是寫在 Excel Application Scope 的 Properties 中的
- 在 Read Cell (UiPath.Excel.Activities.ReadCell)中,excel 的路徑 path 是寫在 Read Cell 的 Properties 中的
【參考】
https://github.com/phw198/OutlookGoogleCalendarSync/issues/220
https://forum.uipath.com/t/uipath-dont-seem-to-recognize-excel-on-my-computer/102882