OOo/LibreOffice UNO / Java: How to get calling spreadsheet cell of a calc function?

It looks like you want to register a listener to a spreadsheet component. To satisfy your goal, you could add the listener to the spreadsheet object it self, or to another nested object that implements an interface that supports an add.+EventListener() method.

Below is a pair (broadcaster/listener) that I can think you could use in your project:

The UNO event model is explained here:

Below are examples of how these listeners are used.

    // Add document window listeners. 

    System.out.println("WriterDoc: Add window listeners."); 

    // Example of adding a document displose listener so the application 
    // can know if the user manually exits the Writer window. 

    document.addEventListener(new XEventListener() { 
        public void disposing(EventObject e) { 
                    "WriterDoc (Event Listener): The document window is closing."); 

    // Example of adding a window listener so the application can know 
    // when the document becomes initially visible (in the case of this 
    // implementation, we will manually set it visible below after we 
    // finish building it). 

    window.addWindowListener(new XWindowListener() { 
        public void windowShown( e) { 
                    "WriterDoc (Window listener): The document window has become visible."); 
        public void windowHidden( e) { } 
        public void disposing( e) { } 
        public void windowResized( e) { } 
        public void windowMoved( e) { } 

Also, the service SheetCellRange supports the interface XModifyBroadcaster. Maybe you could get the desired behavior if you registered a XModifyListener object to it. The object would implement the ‘modified’ method, which receives an EventObject when called. I believe you can get who the caller is from the source property of the EventObject. If the source turns out to be the whole SheetCellRange, you could try to loop through all the cells you wish that be monitored, and add a XModifyListener to each. The SheetCell service also supports the XModifyBroadcaster interface .

Example of use of the XModifyBroadcaster from a CellRange:


Leave a Comment