Bug 148040 - When called through the FunctionAccess service, the INDIRECT function does not process the external reference.
Summary: When called through the FunctionAccess service, the INDIRECT function does no...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Calc (show other bugs)
Version:
(earliest affected)
7.3.1.3 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:7.4.0
Keywords:
Depends on:
Blocks: Macro
  Show dependency treegraph
 
Reported: 2022-03-16 17:05 UTC by Vladimir Sokolinskiy
Modified: 2022-03-17 17:18 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:
Regression By:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Sokolinskiy 2022-03-16 17:05:30 UTC
Create a new Calc document and save, for example, as C:\Temp\test.ods (Windows).

Call macro:

Sub TestIndirect
  Dim oFA, v
  oFA=createUnoService("com.sun.star.sheet.FunctionAccess")  
  v=oFA.callFunction("Indirect", Array("'file:///C:/Temp/test.ods'#$Sheet1.A1"))
End Sub

Result: Error

Expected: The value of the corresponding cell.
Comment 1 Mike Kaganski 2022-03-16 17:33:37 UTC
Repro.
The problem is in ScExternalRefManager::getSingleRefToken, which fails because isLinkUpdateAllowedInDoc returns false for the temporary document used in ScFunctionAccess. There seems to be no property to change that among properties defined for SpreadsheetDocumentSettings service [1] (IsExecuteLinkEnabled feels close, but it is absent in ScFunctionAccess; and isLinkUpdateAllowedInDoc needs the document to have SfxObjectShell, which is not true).

Eike: is it reasonable to introduce such property for SpreadsheetDocumentSettings? Or are there some concerns that would make that unwanted?

[1] https://api.libreoffice.org/docs/idl/ref/servicecom_1_1sun_1_1star_1_1sheet_1_1SpreadsheetDocumentSettings.html
Comment 2 Mike Kaganski 2022-03-16 18:33:33 UTC
(In reply to Mike Kaganski from comment #1)
> is it reasonable to introduce such property for SpreadsheetDocumentSettings?
> Or are there some concerns that would make that unwanted?

Alternatively, isLinkUpdateAllowedInDoc could check rDoc.IsFunctionAccess() and return true (that's easier, and likely makes sense, since enabling that explicitly for function access looks overkill to me).
Comment 3 Eike Rathke 2022-03-16 19:09:57 UTC
Checking rDoc.IsFunctionAccess() in isLinkUpdateAllowedInDoc() if there is no SfxObjectShell looks viable, apparently it could also work without the non-present sfx2::LinkManager in this case, needs to be checked.

However, careful with still obeying the "update links when opening" setting, I think if that is set to Never also the function access shouldn't be allowed to do so. Unfortunately there is no caller parent document here that could be asked to determine the on request and always cases. Probably the interim document should have EnableExecuteLink() set accordingly in ScTempDocSource::CreateDocument().

So then in isLinkUpdateAllowedInDoc() it would be checking
rDoc.IsFunctionAccess() && rDoc.IsExecuteLinkEnabled()
Comment 4 Eike Rathke 2022-03-16 19:17:15 UTC
On the other hand, it's extension or macro/script code that could do anything anyhow..
Comment 5 Commit Notification 2022-03-17 15:20:40 UTC
Mike Kaganski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/7f58df88771767962fc4e98f2b6bed445ab18994

tdf#148040: allow external link update for css.sheet.FunctionAccess

It will be available in 7.4.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 6 Vladimir Sokolinskiy 2022-03-17 17:18:14 UTC
Mike, thank you very much!