[Libreoffice-bugs] [Bug 125042] New: ThisComponent undefined/outdated when a spreadsheet loads

bugzilla-daemon at bugs.documentfoundation.org bugzilla-daemon at bugs.documentfoundation.org
Tue Apr 30 10:50:25 UTC 2019


https://bugs.documentfoundation.org/show_bug.cgi?id=125042

            Bug ID: 125042
           Summary: ThisComponent undefined/outdated when a spreadsheet
                    loads
           Product: LibreOffice
           Version: unspecified
          Hardware: x86-64 (AMD64)
                OS: Windows (All)
            Status: UNCONFIRMED
          Severity: normal
          Priority: medium
         Component: Calc
          Assignee: libreoffice-bugs at lists.freedesktop.org
          Reporter: arminlinder at arminlinder.de

Description:
If you use a formula pointing to a user defined function/macro (tested with:
Basic Macro), which uses the ThisComponent object, the call fails, or gives
unexpected values during the initial recalculation of the spreadsheet cells.

Steps to Reproduce:
1. Sample macro code:

Function TestThisComponent()

        Dim Doc As Object
        Dim Sheet As Object
        Dim Result as String
        Dim S as String

        on Error Goto ExitFunction
rem             Result = "Unable to access XRay"                
rem             xRay ThisComponent
        Result = "Unable to access ThisComomnent"       
        Doc = ThisComponent
        Result = "Unable to access ThisComponent.Sheets(0)"
        Sheet = Doc.Sheets (0)
        Result = "Unable to access Sheet Name"
        S = Sheet.Name
        Result = S
ExitFunction:
        TestThisComponent = Result
End Function

2. In a cell, enter formula: =TestThisComponent()

3. Save and reload the sheet.

Actual Results:
After entering the forumla, everything looks fine, the worksheet name appears
in the cell. When reloading the file, the call/formula fails.

If the reloaded sheet is the only open document, you get  "Unable to access
ThisComponent.Sheets(0)" or "Unable to access ThisComponent", depending on
whether you have the macro editor open or not. If there is another calc
spreadsheet open and activated, you get the other spreadsheet name inserted in
your current document. If any other LibreOffice document (not a spreadsheet) is
active, ThisComponent points to that document, and most likely fails because it
won't have a "Sheets" property.

Expected Results:
The name of the current worksheet stays in the cell if I save and re-load the
file.


Reproducible: Always


User Profile Reset: No



Additional Info:
If I recalculate the spreadsheet cell manually after load [F9], the macro
works.

Conclusions: ThisComponent points to the document object last activated.
Spreadsheet recalculation on document load does obviously take place before the
document gets activated, so this ThisComponent is either uninitialized or
pointing to the wrong document. From testing I'd guess that the initial
recalculation indeed takes place before any document event fires, so there
isn't a workaround.

As far as I have read this behaviour is undocumented, contrary, the
documentation does always state that ThisComponent points to the current
document, which is not correct while the document recalculates upon load.

The only workaround I found is to ignore/suppress any errors, and trigger
another recalculation in the "View Created" event handler which fires after the
document has finished loading. This will, however, have the unwanted
side-effect that the document recalculates twice on load.

Version: 6.1.5.2 (x64)
Build-ID: 90f8dcf33c87b3705e78202e3df5142b201bd805
CPU-Threads: 4; BS: Windows 10.0; UI-Render: Standard; 
Gebietsschema: de-DE (de_DE); Calc: group threaded

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/libreoffice-bugs/attachments/20190430/e9456294/attachment.html>


More information about the Libreoffice-bugs mailing list