Ask Your Question
1

Is it possible to insert a running clock in a Calc spreadsheet cell?

asked 2017-11-28 21:15:07 +0200

Super_C gravatar image

updated 2017-11-28 21:16:51 +0200

Is it possible to insert a running clock in a Calc spreadsheet cell? Digital or Analog are both usable.

edit retag flag offensive close merge delete

Comments

1

Hello @Super_C,

Yes in theory, you could make a threaded timer in Python with an interval of 1 second, then update the value in your Calc cell to the current time. ( i have not tried this myself yet ).

librebel gravatar imagelibrebel ( 2017-11-29 00:00:03 +0200 )edit

2 Answers

Sort by » oldest newest most voted
4

answered 2017-11-29 00:35:46 +0200

m.a.riosv gravatar image

There is a way to do it without macros, that I did a time ago for a question in the Spanish AOo forum.

In a cell introduce =NOW(), give a name to it like 'timer'.
Save the file.
Select the cell where to introduce the clock.
Create a Menu/Sheet/Link to external data, select as data source the own file.
Select the 'timer' in the 'Available Tables/Ranges'
Mark Update interval and fix the seconds you like for update the clock.
Ok

Sample timer.ods

image description

edit flag offensive delete link more

Comments

1

+1 awesome trick!

librebel gravatar imagelibrebel ( 2017-11-29 01:04:36 +0200 )edit

One disadvantage is that it stops working if the file is renamed, whereas a macro would not have this problem. However, avoiding macros is an advantage, so it's a tradeoff. Anyway, I did not realize before that this solution can work even with reference to the same file.

Jim K gravatar imageJim K ( 2017-11-29 06:00:22 +0200 )edit
1

answered 2017-11-29 06:33:28 +0200

Jim K gravatar image

updated 2017-11-29 06:48:31 +0200

As @librebel mentioned, one way to do this is with a threaded Python macro. From my answer at https://stackoverflow.com/a/44988206/...:

Assign keep_recalculating_thread to the Open Document event.

import time
from threading import Thread
import uno

def keep_recalculating_thread(action_event=None):
    t = Thread(target = keep_recalculating)
    t.start()

def keep_recalculating():
    oDoc = XSCRIPTCONTEXT.getDocument()
    while hasattr(oDoc, 'calculateAll'):
        oDoc.calculateAll()
        time.sleep(5)

g_exportedScripts = keep_recalculating_thread,

Instead of calculateAll(), I also tried updating a single cell containing NOW() as recommended here. My hope was that only a single cell would need to be changed.

oCell.setFormula(oCell.getFormula() + " ")

This worked too, but it made all cells with NOW() and RAND()change anyway, so it does not seem to be any more efficient. See https://help.libreoffice.org/Calc/Rec....

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-11-28 21:15:07 +0200

Seen: 762 times

Last updated: Nov 29 '17