[Solved][Calc] CurrentController not available for function

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Bidouille
Volunteer
Posts: 574
Joined: Mon Nov 19, 2007 10:58 am
Location: France

[Solved][Calc] CurrentController not available for function

Post by Bidouille »

Hello,

Tested with AOO 4.1.3 and Win7 x64 Pro

I stored this function in a spreadsheet:

Code: Select all

Function TEST(sCell)
    oDoc = thisComponent
    oCtrl = oDoc.currentController
    oSheet = oCtrl.activeSheet
    oCell = oSheet.getCellRangeByName(sCell)
    Test = sCell & " contains: " & oCell.string
End function
This works if I input this formula:

Code: Select all

=TEST("C1")
But when I (re)load the document, I got: "Error, undefined object variable"

I don't know why CurrentController is void.
Functions must be calculated after document is loaded.
Did you think is a bug?
Attachments
function.ods
(9.48 KiB) Downloaded 347 times
Last edited by Bidouille on Tue Jun 16, 2020 11:56 am, edited 4 times in total.
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Calc] CurrentController is not available for function

Post by Villeroy »

The document is calculated before rendering. There is no controller when this happens. Use ordinary references. =TEST(A1) refers to A1 on the same sheet as the formula cell.
If you need another type of referencing because you need access to the cell object you may consider this: viewtopic.php?f=21&t=2762
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Bidouille
Volunteer
Posts: 574
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: [Solved][Calc] CurrentController not available for funct

Post by Bidouille »

I bump this thread.

Seems that document works perfectly with LibO.
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Calc] CurrentController not available for function

Post by Villeroy »

Not with LO5.4
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Bidouille
Volunteer
Posts: 574
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: [Calc] CurrentController not available for function

Post by Bidouille »

Click here to see animation
Click here to see animation
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Calc] CurrentController not available for function

Post by Villeroy »

Strange.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
JohnSUN-Pensioner
Volunteer
Posts: 876
Joined: Fri Jan 14, 2011 1:21 pm
Location: Kyiv, Ukraine

Re: [Calc] CurrentController not available for function

Post by JohnSUN-Pensioner »

It is possible that in LiO 5.4 this option was incorrectly processed
UDFormula.png
UDFormula.png (7.42 KiB) Viewed 4199 times
(now, in 6.4.3.2 I was not able to repeat this trick) - in the animated GIF we see not the result of the function recalculation, but the stored value.

Anyway, or your

Code: Select all

If (isNull (oCtrl)) then Exit function
or

Code: Select all

On Error Resume Next
combined with the first row

Code: Select all

TEST = "Press Ctrl+Shift+F9"
allows to partially solve the problem.
I am sure that everyone (except novice users) will agree that a complete solution to this problem is a complete rejection of the use of such macros.
I may not have a lot to give but what I got I'll give to you...
Apache OpenOffice 4.1.5, LibreOffice 6.4.4.2 (x64) on Windows 7
If you think that I did not answer your question, make allowances for my imperfect English
User avatar
Lupp
Volunteer
Posts: 3542
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [Calc] CurrentController not available for function

Post by Lupp »

See also:
ask90364activeSheet_1.ods
(11.08 KiB) Downloaded 226 times
On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Bidouille
Volunteer
Posts: 574
Joined: Mon Nov 19, 2007 10:58 am
Location: France

Re: [Calc] CurrentController not available for function

Post by Bidouille »

JohnSUN-Pensioner wrote:now, in 6.4.3.2 I was not able to repeat this trick
Thanks for this new test.
JohnSUN-Pensioner wrote:

Code: Select all

If (isNull (oCtrl)) then Exit function
or

Code: Select all

On Error Resume Next
combined with the first row

Code: Select all

TEST = "Press Ctrl+Shift+F9"
allows to partially solve the problem.
Well I can run UNO command to recalculate: viewtopic.php?f=45&t=54868
Post Reply