My code is saving source file in ods format using OpenOffice API and switching off gridlines in the sheet, but when I am trying to convert ods format to xls or xlsx format they are switched on again. The problem occurs when OpenOffice service (soffice.bin) instance is running in Hidden mode. If it is not running on Hidden mode then conversion works only for xls format.
OS windows server 2012, OpenOffice 4.1.2.
See my code fragment bellow.
Code: Select all
public void convertDocumentToXlsx(byte[] buffer, OfficeContext context) throws Exception {
log.info("Getting stream");
XInputStream xStream = new ByteArrayToXInputStreamAdapter(buffer);
PropertyValue[] args = new PropertyValue[2];
args[0] = new PropertyValue();
args[0].Name = "InputStream";
args[0].Value = xStream;
args[0].State = PropertyState.DIRECT_VALUE;
args[1] = new PropertyValue();
args[1].Name = "Hidden";
args[1].Value = Boolean.TRUE;
XComponentLoader xComponentLoader = (XComponentLoader) UnoRuntime.queryInterface(XComponentLoader.class, context.getService(OfficeUtils.SERVICE_DESKTOP));
XComponent xComponent = xComponentLoader.loadComponentFromURL("private:stream", "_blank", 0, args);
XStorable xStorable = (XStorable) UnoRuntime.queryInterface(XStorable.class, xComponent);
PropertyValue[] storeArgs = new PropertyValue[1];
storeArgs[0] = new PropertyValue();
storeArgs[0].Name = "FilterName";
storeArgs[0].Value = "Calc MS Excel 2007 XML";
xStorable.storeToURL(new File("c:/fakePath").toURI().toString(), args);
}