I'm currently working on program which fills a .ods-file with xml-data. From this data a chart is generated. Now I want to export the chart/diagram to png/jpeg by using the java uno api.
So far my efforts are this:
Code: Select all
XComponent document = xComponentLoader.loadComponentFromURL("private:stream/scalc", "_blank", 0,
conversionProperties);
XSpreadsheetDocument xSpreadsheetDocument = UnoRuntime.queryInterface(XSpreadsheetDocument.class, document);
XSpreadsheets xSpreadsheets = xSpreadsheetDocument.getSheets();
Object sheet = xSpreadsheets.getByName("Chart");
XSpreadsheet xSpreadsheet = UnoRuntime.queryInterface(XSpreadsheet.class, sheet);
XTableChartsSupplier xTableChartsSupplier = UnoRuntime.queryInterface(XTableChartsSupplier.class, xSpreadsheet);
Object chart = xTableChartsSupplier.getCharts()
.getByName(xTableChartsSupplier.getCharts().getElementNames()[0]);
XTableChart xTableChart = UnoRuntime.queryInterface(XTableChart.class, chart);
XEmbeddedObjectSupplier xEmbeddedObjectSupplier = UnoRuntime.queryInterface(XEmbeddedObjectSupplier.class,
xTableChart);
XInterface xInterface = xEmbeddedObjectSupplier.getEmbeddedObject();
XChartDocument xChart = UnoRuntime.queryInterface(XChartDocument.class, xInterface);
Object oGraphicExportFilter = xComponentContext.getServiceManager()
.createInstanceWithContext("com.sun.star.drawing.GraphicExportFilter", xComponentContext);
XExporter xExporter = UnoRuntime.queryInterface(XExporter.class, oGraphicExportFilter);
XComponent xComp = UnoRuntime.queryInterface(XComponent.class, xChart.getDiagram());
xExporter.setSourceDocument(xChart);
// xExporter.setSourceDocument(xComp); isn't working either
Code: Select all
xExporter.setSourceDocument(xChart);
Code: Select all
com.sun.star.lang.IllegalArgumentException:
at com.sun.star.lib.uno.environments.remote.Job.remoteUnoRequestRaisedException(Job.java:173)
at com.sun.star.lib.uno.environments.remote.Job.execute(Job.java:139)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:334)
at com.sun.star.lib.uno.environments.remote.JobQueue.enter(JobQueue.java:303)
at com.sun.star.lib.uno.environments.remote.JavaThreadPool.enter(JavaThreadPool.java:87)
at com.sun.star.lib.uno.bridges.java_remote.java_remote_bridge.sendRequest(java_remote_bridge.java:636)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.request(ProxyFactory.java:146)
at com.sun.star.lib.uno.bridges.java_remote.ProxyFactory$Handler.invoke(ProxyFactory.java:128)
at com.sun.proxy.$Proxy14.setSourceDocument(Unknown Source)
Thanks for helping in advance.
Regards,
Oliver