Repository: nvaccess/nvda

Issue:
Formula not reported in excel 2007
<!--
Please thoroughly read NVDA's wiki article on how to fill in this template, including how to provide the required files.
Issues may be closed if the required information is not present.
https://github.com/nvaccess/nvda/wiki/Github-issue-template-explanation-and-examples
-->

### Steps to reproduce:
1. Create a new sheet in MS excel 2007
1. Add a simple formula to a cell and press enter
1. Use arrow keys to return to the cell with the formula

### Actual behavior:
The result of the formula is reported (calculated value). "has formula" is not announced.
Pressing F2 allows us to confirm the presence of the formula.

### Expected behavior:
"has formula" should be announced.

### System configuration
#### NVDA installed/portable/running from source:
Installed

#### NVDA version:
`alpha-16976,7fc6c71f`

#### Windows version:
Microsoft Windows
Version 1803 (OS Build 17134.648)

#### Name and version of other software in use when reproducing the issue:
Microsoft Office Excel 2007 (12.0.6787.5000) SP3 MSO (12.0.6785.5000) 

#### Other information about your system:

### Other questions
#### Does the issue still occur after restarting your PC?
Yes

#### Have you tried any other versions of NVDA?
2018.4 works as expected.


Discussion:
Some alternatives that can be used to work around this issue can be found in https://github.com/nvaccess/nvda/issues/7899. Specifically, pressing ```control + ` (accent grave)``` in excel will toggle between showing formulae in (all) cells rather than the result. 
Does inserting a comment on the cell, cause NVDA to announce "has comment"? If not, I am guessing this is a broader problem where NVDA is not able to inject into Excel at all. 
No, "has comment" is also not reported. The NVDA log contains the following:

The most relevant thing in the log seems to be (there a few similar such errors):
```
DEBUGWARNING - eventHandler.executeEvent (14:31:39.773):
error executing event: typedCharacter on <NVDAObjects.window.excel.ExcelCell object at 0x0563C6B0> with extra args of {'ch': u'l'}
Traceback (most recent call last):
  File "eventHandler.pyc", line 155, in executeEvent
  File "eventHandler.pyc", line 92, in __init__
  File "eventHandler.pyc", line 100, in next
  File "NVDAObjects\window\excel.pyc", line 1342, in event_typedCharacter
  File "baseObject.pyc", line 47, in __get__
  File "baseObject.pyc", line 147, in _getPropertyViaCache
  File "NVDAObjects\window\excel.pyc", line 871, in _get_states
  File "comtypesMonkeyPatches.pyc", line 35, in new__getattr__
  File "comtypes\client\lazybind.pyc", line 168, in __getattr__
  File "comtypes\automation.pyc", line 729, in _invoke
COMError: (-2147418111, 'Call was rejected by callee.', (None, None, None, 0, None)
```

Resolving patch:
diff --git a/source/NVDAObjects/window/excel.py b/source/NVDAObjects/window/excel.py
--- a/source/NVDAObjects/window/excel.py
+++ b/source/NVDAObjects/window/excel.py
@@ -7,7 +7,7 @@
 import abc
 from six import with_metaclass
 import ctypes
-from comtypes import COMError
+from comtypes import COMError, BSTR
 import comtypes.automation
 import wx
 import time
@@ -1118,7 +1118,8 @@ def iterate(self):
 		count=collectionObject.count
 		cellInfos=(ExcelCellInfo*count)()
 		numCellsFetched=ctypes.c_long()
-		NVDAHelper.localLib.nvdaInProcUtils_excel_getCellInfos(self.document.appModule.helperLocalBindingHandle,self.document.windowHandle,collectionObject._comobj,self.cellInfoFlags,count,cellInfos,ctypes.byref(numCellsFetched))
+		address=collectionObject.address(True,True,xlA1,True)
+		NVDAHelper.localLib.nvdaInProcUtils_excel_getCellInfos(self.document.appModule.helperLocalBindingHandle,self.document.windowHandle,BSTR(address),self.cellInfoFlags,count,cellInfos,ctypes.byref(numCellsFetched))
 		for index in xrange(numCellsFetched.value):
 			ci=cellInfos[index]
 			if not ci.address:
@@ -1147,7 +1148,8 @@ def _get_excelCellInfo(self):
 			return None
 		ci=ExcelCellInfo()
 		numCellsFetched=ctypes.c_long()
-		res=NVDAHelper.localLib.nvdaInProcUtils_excel_getCellInfos(self.appModule.helperLocalBindingHandle,self.windowHandle,self.excelCellObject._comobj,NVCELLINFOFLAG_ALL,1,ctypes.byref(ci),ctypes.byref(numCellsFetched))
+		address=self.excelCellObject.address(True,True,xlA1,True)
+		res=NVDAHelper.localLib.nvdaInProcUtils_excel_getCellInfos(self.appModule.helperLocalBindingHandle,self.windowHandle,BSTR(address),NVCELLINFOFLAG_ALL,1,ctypes.byref(ci),ctypes.byref(numCellsFetched))
 		if res!=0 or numCellsFetched.value==0:
 			return None
 		return ci


Test patch: