Code: Select all
XComponentContext xcomponentcontext = Bootstrap.createInitialComponentContext(null);
XUnoUrlResolver urlResolver = UnoUrlResolver.create(xcomponentcontext);
Object initialObject = urlResolver.resolve("uno:socket,host=localhost,port=8100;urp;StarOffice.ServiceManager");
XMultiComponentFactory xOfficeFactory = (XMultiComponentFactory) UnoRuntime.queryInterface(XMultiComponentFactory.class, initialObject);
XPropertySet xProperySet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xOfficeFactory);
Object oDefaultContext = xProperySet.getPropertyValue("DefaultContext");
XComponentContext xOfficeComponentContext = (XComponentContext) UnoRuntime.queryInterface(XComponentContext.class, oDefaultContext);
Object oDesktop = xOfficeFactory.createInstanceWithContext("com.sun.star.frame.Desktop",xOfficeComponentContext);
XDesktop xDesktop = (XDesktop) UnoRuntime.queryInterface(XDesktop.class, oDesktop);
File f = new File(fileNamePath);
if (!f.canRead() || f == null || !f.exists()) {
try {
errorJson.put("Msg", "Cannot load template:" + fileNamePath);
errorJson.put("Status", "Error");
excelDataArr.put(errorJson);
} catch (JSONException ex) {
ex.printStackTrace();
}
return excelDataArr.toString();
}
xCompLoader = (XComponentLoader) UnoRuntime.queryInterface(com.sun.star.frame.XComponentLoader.class, xDesktop);
String docURL = "file:///" + fileNamePath.replace(File.separatorChar, '/');
PropertyValue[] propertyValues = new PropertyValue[0];
propertyValues = new PropertyValue[1];
propertyValues[0] = new PropertyValue();
propertyValues[0].Name = "Hidden";
propertyValues[0].Value = new Boolean(false);
XComponent xComp = xCompLoader.loadComponentFromURL(docURL, "_blank", 0, propertyValues); //returns null
Thank you.