Repository: nvaccess/nvda

Issue:
after installing nvda next 14998 can not edit cells in excel
### Steps to reproduce:
Install the nvda next 14998.
Open a spreadsheet in excel.
press f2 on any cell in the worksheet.
### Expected behavior:
The nvda should read the characters entered in the cell when in edit mode.

### Actual behavior:
after typing a content in the cell and pressing f2 to edit the cell, and trying to walk with the arrows by the typed text the nvda informs unknown, and does not read the typed text.

### System configuration:
NVDA version:
next 14998

NVDA Installed or portable:
instaled

Other information:
> Example: Running in a VM
it was necessary to reinstall the office so that nvda will read the texts typed in the cells again.
I tried to reinstall the nvda but it did not work.
I tried installing a previous version of nvda 2018.1 more unsolvable.
I tried to repair the oficce more also not solve.
The problem only resolved after you completely removed the office and re-installed the office.
Windows version:
windows 10 16299.309

Name and version of other software in use when reproducing the issue:
office 2016
### Other questions:

Does the issue still occur after restarting your PC?
yes
Have you tried any other versions of NVDA?
> Please list them and the result
2018.1


Discussion:
I also tried using the
Run COM Registration Fixing tool ...
in the nvda tools menu but it did not work.
Again, problem solved after uninstalling and reinstalling office 2016.
I can reproduce this with Next 14987, master and 2018.1 when running from source. I could be an issue in a specific Office build?

@fernando-jose-silva: Is this Office 365?
I'm currently at Office build 2016.0.91.26

cc @dkager @bramd
Used Excel this afternoon and didn't see this issue, had some strange lag though that I should investigate. The laptop I used is still at the office, so can't check exact builds right now.
I can reproduce with master and Office 2016 16.0.9126.2116.
I can also reproduce this.

I thought it was originally caused on my machine because I installed 
Skype for business Basic (which is based on an earlier version of Office 
2016).

But it is now possible that it is caused by the COM registration tool.

Can someone for whom Excel editing still works, please run with Next, 
and run the COM registration tool in NVDA, if you have not installed 
Next lately. Then sign out and or reboot, and try Excel again.

Just ran the COM registration tool and signed out/in again. Editing 
still works as expected.

I did update regular Skype last week, which would be a terrible coincidence. :)
I'm using office 2016 it's not the 360 version.
I re-installed Office 2016 (Windows store version) and the issue was 
fixed for me. Re-running the COM registration tool and signing out/in 
after that did not cause the issue to reoccur.

I notice that a security update for Microsoft Office 2016 was installed 
around the same time things broke for me. Normally those security 
updates would not apply to my installation as it is from the Windows 
Store, but as I had Skype for business Basic also installed which is 
based on Office 2016 Desktop, I happened to get it.



That sounds like the registration tool running at start up to me.
 Brian

I'm at Excel 16.0.9126.2109 at my work laptop. Here, the issue does not occur with latest next.
At the home laptop, I reinstalled Office and I'm now also at Excel 16.0.9126.2109. The issue still persists though. Skype for business is also a part of this new Office installation.
The problem occurs on my desktop to which Windows did an update a couple of days ago.  It does not happen on my notebook which has not yet received the update.  Using 2018.1.1 on both machines.  Looks like the office uninstall/reinstall is the fix for now - tedious.
I neglected to mention that I am using Office 365.  The updates that were applied to the desktop have just been applied to the notebook:
2018-04 Cumulative Update for Windows 10
Version 1709 for x64-based Systems (KB4093112)

2018-04 Security Update for Adobe Flash Player for
Windows 10 Version 1709 for x64-based Systems
KB4093110)

I can still edit Excel files on that machine.  That puts my update theory into severe doubt.

I'm sure when I first heard about this issue, editing was working fine for me.  I just had another look and now I'm getting the "Unknown" issue as well.  I am using an installed copy of NVDA Next so that has updated a couple of times.  I ran a temporary copy of 2018.1.1 and the issue is occurring for me with that as well.

I'm using Windows 10 fast insider build 17134.1 and Office 365 which should be up to date.  The account screen tells me Version 1803 Build 9126.2152 Click to run, Monthly channel.

I'm using the OneCore synth today, but swapping to eSpeak NG doesn't seem to change anything.

Looking at my NVDA log from where I pressed F2, then left arrow a couple of times:

IO - inputCore.InputManager.executeGesture (09:53:54.053):
Input: kb(desktop):f2
DEBUGWARNING - IAccessibleHandler.accessibleObjectFromEvent (09:53:54.079):
oleacc.AccessibleObjectFromEvent with window 133528, objectID 30542 and childID 0: [Error -2147467259] Unspecified error
DEBUGWARNING - IAccessibleHandler.accessibleObjectFromEvent (09:53:54.081):
oleacc.AccessibleObjectFromEvent with window 133528, objectID 30546 and childID 0: [Error -2147467259] Unspecified error
DEBUG - synthDrivers.oneCore.SynthDriver.cancel (09:53:54.084):
Cancelling
DEBUG - synthDrivers.oneCore.SynthDriver._processQueue (09:53:54.088):
Queue empty, done processing
DEBUGWARNING - NVDAObjects.window.excel.ExcelBrowseModeTreeInterceptor._get_isAlive (09:53:54.148):
could not compare sheet names
Traceback (most recent call last):
  File "NVDAObjects\window\excel.pyo", line 452, in _get_isAlive
  File "comtypesMonkeyPatches.pyo", line 35, in new__getattr__
  File "comtypes\client\lazybind.pyo", line 168, in __getattr__
  File "comtypes\automation.pyo", line 729, in _invoke
COMError: (-2147418111, 'Call was rejected by callee.', (None, None, None, 0, None))
DEBUG - treeInterceptorHandler.killTreeInterceptor (09:53:54.148):
Killed treeInterceptor: <NVDAObjects.window.excel.ExcelBrowseModeTreeInterceptor object at 0x04FF0D50>
IO - speech.speak (09:53:54.153):
Speaking [LangChangeCommand (u'en_CA'), u'unknown']
DEBUG - synthDrivers.oneCore.SynthDriver._processQueue (09:53:54.164):
Begin processing speech
DEBUG - synthDrivers.oneCore.SynthDriver._callback (09:53:54.173):
Done pushing audio
DEBUG - synthDrivers.oneCore.SynthDriver._processQueue (09:53:54.174):
Calling idle on audio player
DEBUG - synthDrivers.oneCore.SynthDriver._processQueue (09:53:55.092):
Queue empty, done processing
IO - inputCore.InputManager.executeGesture (09:53:55.278):
Input: kb(desktop):leftArrow
DEBUG - synthDrivers.oneCore.SynthDriver.cancel (09:53:55.288):
Cancelling
IO - inputCore.InputManager.executeGesture (09:53:55.780):
Input: kb(desktop):leftArrow
IO - inputCore.InputManager.executeGesture (09:53:56.206):
Input: kb(desktop):leftArrow

One quick update on this,

a suggestion from Pranav on the Users list was to uncheck "Allow editing in cells" on the "Advanced" page of Excel's options.  This was checked by default, and I hadn't previously touched it, but unchecking it appears to have fixed the issue for me for now.  I haven't tested extensively (I haven't restarted etc), but just at the moment it is working again.
Unchecking Allow editing directly in cells also works around the issue here.  I have restarted the machine.  There was an initial glitch when trying to open an Excel file on restarting, but all seems good.  NVDA now reports "Formula bar editing when pressing F2.

The Allow editing directly in cells is still checked on my notebook and the problem has not occurred there.
Is this resolved, or is there still an issue here?
It seems that unchecking the option to allow editing in cells seems to be a workaround for the issue, although it's more a band-aid than actually fixing it.  Whether it's worth saying that is enough, I guess depends on what the underlying issue is, and possibly also whether the issue would still be relevant as and when we move to using UIA for Excel.
Yes, I can still reproduce the issue with the latest "next" snapshot of NVDA and the latest stable Excel 2016 (Office 365 version). Not only that, but almost each time when I close a file in Excel with Control+F4, Excel crashes. It does not crash with NVDA not running. But it also does crash with Narrator running, so the problem is somewhere in Excel/Office and not NVDA itself. Narrator at least reads the cell content when editing, even if the editing is done directly in the cell itself.
I can confirm everything you mentioned except that Excel does not crash on exit with a screen reader running.  I just tried reinstalling Office, which did not change anything.  Not surprising, as it is not a clean install.  No problems editing cells on my notebook machine, which seems to have all the updates of the desktop.  I agree that it is not an NVDA issue per se - Microsoft has changed something.
A further discovery which may or may not shed more light.  I logged into my wife's account on the same machine and the problem does not occur there.  Weird!

Hello,
I just would like to use excel for a task. I am facing this issue. I am using the last master of nvda (master-15110). I have just reinstall office 365. After I have run the com registration tool and I have reboot my laptop. The issue still occur. ²
@clementb49 See this comment: https://github.com/nvaccess/nvda/issues/8146#issuecomment-383440531 if you turn off allow editing in cells it should fix the problem.  Also see https://www.nvaccess.org/post/in-process-26th-april-2018/ for more information on the effects of that workaround.

I don't think the crashing is related.  Could someone experiencing it (I'm not able to replicate it here either) could please create a new issue and include a copy of the NVDA log.
I was the one with the crashing bug of Excel with a screen reader running. But now I can't reproduce it anymore. When and if I do reproduce it, I'll provide NVDA's log and a memory dump from Excel, if necessary.
I've seen this issue with Excel 2013. More importantly, the workaround to disable inline cell editing does not work, as it seems the formula bar isn't accessible. In my opinion this raises the importance of this issue a bit.
@michaeldcurran: Would you agree with a p2 here?
Yes. P2 sounds appropriate.


The point that is worth reiterating here is that it is not something that broke in NVDA which caused the issue.  I do not have the problem on one machine and on the other it only occurs in one account.  Both machines have been through the same upgrade path.  If an NVDA work-around can be found, well and good.  However, it would be preferable to find out what happens in the system to create the problem.

Andrew

note that the issue #9137 is an example of the clean fresh office 365/windows installation.
This issue i have reported aksi frin ibe yser from the polish community
I'm still having this issue. I'm stil running 2018.3.2 however. My excel version is Microsoft® Excel® for Office 365 MSO (16.0.10730.20264) 32-bit.
This is a fresh installation of office 365 ProPlus on a fresh windows 10 1803 image.
I was also seeing the issue on my older work machine running the same software, but with windows 7 instead of 10.
I've just tried with JFW 2018 and that works fine. There's a little lag, but that's normal with excel these days.

Resolving patch:
diff --git a/source/NVDAObjects/UIA/__init__.py b/source/NVDAObjects/UIA/__init__.py
--- a/source/NVDAObjects/UIA/__init__.py
+++ b/source/NVDAObjects/UIA/__init__.py
@@ -758,7 +758,11 @@ def _prefetchUIACacheForPropertyIDs(self,IDs):
 				cacheRequest.addProperty(ID)
 			except COMError:
 				log.debug("Couldn't add property ID %d to cache request, most likely unsupported on this version of Windows"%ID)
-		cacheElement=self.UIAElement.buildUpdatedCache(cacheRequest)
+		try:
+			cacheElement=self.UIAElement.buildUpdatedCache(cacheRequest)
+		except COMError:
+			log.debugWarning("IUIAutomationElement.buildUpdatedCache failed given IDs of %s"%IDs)
+			return
 		for ID in IDs:
 			elementCache[ID]=cacheElement
 
diff --git a/source/_UIAHandler.py b/source/_UIAHandler.py
--- a/source/_UIAHandler.py
+++ b/source/_UIAHandler.py
@@ -279,10 +279,15 @@ def IUIAutomationEventHandler_HandleAutomationEvent(self,sender,eventID):
 			obj=focus
 		eventHandler.queueEvent(NVDAEventName,obj)
 
+	# The last UIAElement that received a UIA focus event
+	# This is updated no matter if this is a native element, the window is UIA blacklisted by NVDA, or  the element is proxied from MSAA 
+	lastFocusedUIAElement=None
+
 	def IUIAutomationFocusChangedEventHandler_HandleFocusChangedEvent(self,sender):
 		if not self.MTAThreadInitEvent.isSet():
 			# UIAHandler hasn't finished initialising yet, so just ignore this event.
 			return
+		self.lastFocusedUIAElement=sender
 		if not self.isNativeUIAElement(sender):
 			return
 		import NVDAObjects.UIA
diff --git a/source/appModules/excel.py b/source/appModules/excel.py
--- a/source/appModules/excel.py
+++ b/source/appModules/excel.py
@@ -4,9 +4,44 @@
 # This file may be used under the terms of the GNU General Public License, version 2 or later.
 # For more details see: https://www.gnu.org/licenses/gpl-2.0.html
 
+import time
+import eventHandler
+import api
+import UIAHandler
+from NVDAObjects.UIA import UIA
+import controlTypes
 import appModuleHandler
 from NVDAObjects.window import DisplayModelEditableText
 from NVDAObjects.window.edit import UnidentifiedEdit
+from NVDAObjects.window import Window
+from NVDAObjects.window.excel import ExcelCell
+
+class Excel6(Window):
+	"""
+	The Excel cell edit window.
+	If it is not accessible (no displayModel) then wait for the CellEdit UIA element to get focus and redirect to that.
+	"""
+
+	def _get_focusRedirect(self):
+		if self.role==controlTypes.ROLE_UNKNOWN:
+			# The control is inaccessible, try several times to find the CellEdit UIA element with focus and use that instead.
+			for count in xrange(10):
+				if count>=1:
+					api.processPendingEvents(processEventQueue=False)
+					if eventHandler.isPendingEvents("gainFocus"):
+						return
+					time.sleep(0.05)
+				e=UIAHandler.handler.lastFocusedUIAElement
+				if e and e.cachedAutomationID=="CellEdit":
+					obj=UIA(UIAElement=e)
+					oldFocus=api.getFocusObject()
+					if isinstance(oldFocus,ExcelCell):
+						# Set the edit control's parent as the cell that previously had focus. I.e. the cell being edited.
+						# otherwise a whole bunch of UIA focus ancestors for the edit control will be reported.
+						obj.parent=oldFocus
+					# Cache this for as long as this object exists.
+					self.focusRedirect=obj
+					return obj
 
 class AppModule(appModuleHandler.AppModule):
 
@@ -19,3 +54,5 @@ def chooseNVDAObjectOverlayClasses(self, obj, clsList):
 			except ValueError:
 				pass
 			clsList.insert(0, DisplayModelEditableText)
+		if windowClass=="EXCEL6":
+			clsList.insert(0,Excel6)


Test patch: