Issue with Excel COM when used by JavaScript as hostObject in a WebView2 control

0

I have an ExcelDNA project with a custom taskpane that contains a WebView2 control.
(cf. demo project here: https://github.com/alaincao/ExcelDNASamples/tree/automation_issue_cs_js/CustomTaskPane)
Then, I am trying to control the Excel application using JavaScript. So, in the C# side, I expose its reference using AddHostObjectToScript()

wv.CoreWebView2.AddHostObjectToScript( "excel", ExcelDna.Integration.ExcelDnaUtil.Application );

Problems arise when I try to use that hostObject from the JavaScript. Some functions seems to work OK, but others don't.
Eg., this does set current cell's value without issue:
chrome.webview.hostObjects.excel.ActiveCell.Value = 123;
but this:
chrome.webview.hostObjects.excel.ActiveCell.Cells(2, 2).Value = 123;
crashes with

VM6:2 Uncaught Error: Member not found. (0x80020003)
Uncaught (in promise) {remoteObjectId: 0, methodName: "", parameters: {�}, callId: 16}
Promise.then(async)
createPublicObject @VM6: 1
applyHostFunction @VM6: 1
apply @VM6: 1
    (anonymous) @VM289: 1

From what I could find, it seems it knows there's something called .Cells but is unable to invoke it.
(ie. is it even a function?)

I am not familiar with COM at all. Does anyone knows how to correctly interact with Excel's reference or if this would even be possible?

excel-dna
webview2
asked on Stack Overflow May 6, 2021 by wcxyiany

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0