public static String expandMacro(XMultiServiceFactory xMSF, String expand) throws java.lang.Exception{
try {
XPropertySet xPS = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xMSF);
XComponentContext xContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, xPS.getPropertyValue("DefaultContext"));
XMacroExpander xME = (XMacroExpander) UnoRuntime.queryInterface(XMacroExpander.class, xContext.getValueByName("/singletons/com.sun.star.util.theMacroExpander"));
return xME.expandMacros(expand);
}
catch(Exception e) {
throw new Exception("could not expand macro: " + e.toString(),e);
}