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.
Reloading is easy. The trick is to ignore changes, and a simple solution is given at http://ooo-forums.apache.org/en/forum/viewtopic.php?t=27962&p=127331.
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.com/How-to-reload-current-opened-document-via-API-td2773542.html.
Hello how i can add this Macro to my “LibreOffice 5 - Calc” and run it every 10min?
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
.