Ask Your Question
1

How to reload file via macro on Calc

asked 2018-03-01 04:56:22 +0200

thomehhh gravatar image

updated 2020-09-01 13:04:48 +0200

Alex Kemp gravatar image

Does anybody knows how to reload the active file from the last time it was saved, using macro, in libreoffice Calc? It would be something like clicking on File -> Refresh, but this time without the confirmation window. Thanks in advance.

edit retag flag offensive close merge delete

3 Answers

Sort by » oldest newest most voted
3

answered 2018-03-01 16:44:26 +0200

Jim K gravatar image

updated 2018-03-01 16:46:25 +0200

Reloading is easy. The trick is to ignore changes, and a simple solution is given at http://ooo-forums.apache.org/en/forum....

Sub SilentlyReload
    ThisComponent.setModified(False)  'Ignore changes'
    document = ThisComponent.CurrentController.Frame
    dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
    dispatcher.executeDispatch(document, ".uno:Reload", "", 0, Array())
End Sub

See also http://openoffice.2283327.n4.nabble.c....

edit flag offensive delete link more
1

answered 2020-02-25 05:51:34 +0200

sjaguar gravatar image

updated 2020-02-25 05:54:06 +0200

I find the "How to reload current opened document via API" thread referenced by Jim K quite vague and not directly related to macros.

However, since both the question and the thread relate to dispatching a .uno:Reload command, I would like to share my findings related to dispatching a reload using Java code.

The following Java function successfully reloads a component:

   /**
    * Reloads a document via the dispatch API.
    *
    * @param component some component previously loaded
    * 
    * @throws Exception 
    */
   public static void dispatchReload( XComponent component )
     throws Exception
   {
      XController        c;
      XDispatch          d;
      XDispatchHelper    dh;
      XFrame             doc;
      XNotifyingDispatch dn;
      XDispatchProvider  dp;
      XModel             m;
      Object             o;
      PropertyValue[]    pv;

      /*
       * UNO "casting" and obtaining the references required:
       * 
       * a reference to the document as a dispatch provider
       * is required to use the dispatch API
       */
      m   = (XModel)UnoRuntime.queryInterface( XModel.class, component );
      c   = m.getCurrentController();
      doc = c.getFrame();
      dp  = (XDispatchProvider)UnoRuntime.queryInterface( XDispatchProvider.class, doc );
      o   = componentFactory.createInstanceWithContext( c, componentContext );
      dh  = (XDispatchHelper)UnoRuntime.queryInterface( XDispatchHelper.class, o );

      pv    = new PropertyValue[1];
      pv[0] = new PropertyValue();

      dh.executeDispatch( dp, ".uno:Reload", "", 0, pv );
 }

but after executing the dispatch, an attempt to read from component results in a com.sun.star.uno.RuntimeException.

edit flag offensive delete link more
-1

answered 2019-03-04 09:04:47 +0200

fofi2k gravatar image

Hello how i can add this Macro to my "LibreOffice 5 - Calc" and run it every 10min?

edit flag offensive delete link more

Comments

Answers should be answers, not questions. See guidelines for asking.

Jim K gravatar imageJim K ( 2019-04-10 17:56:02 +0200 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2018-03-01 04:56:22 +0200

Seen: 1,603 times

Last updated: Feb 25 '20