Page 1 of 1

ODS conversion to xls/xlsx problem

PostPosted: Tue Jul 24, 2018 7:19 pm
by ototbeli
Hello, i have a problem regarding the OpenOffice spreadsheet conversion to “xls” and ‘xlsx” format.

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   Expand viewCollapse view
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);

}

Re: ODS conversion to xls/xlsx problem

PostPosted: Tue Jul 24, 2018 7:27 pm
by Zizi64
Your signature is:
openoffice 4.1.2

The Apache OpenOffice can not save into the MS OOXML formats. Are you using LibreOffice really?

Re: ODS conversion to xls/xlsx problem

PostPosted: Tue Jul 24, 2018 8:36 pm
by John_Ha
You should always save AOO or LO spreadsheets in .ods format; and AOO and LO text documents in .odt format etc.

See [Tutorial] Differences between Writer and MS Word files for the many reasons why - it is even more important for spreadsheets.

Re: ODS conversion to xls/xlsx problem

PostPosted: Tue Jul 24, 2018 11:03 pm
by ototbeli
#Zizi64 yes i'm using LibreOffice for xlsx, but OpenOffice also has the same impact when converting ods to xls format.

Re: ODS conversion to xls/xlsx problem

PostPosted: Wed Jul 25, 2018 6:16 am
by Zizi64
If it is not running on Hidden mode then conversion works only for xls format.

I suppose it only: appearing of the grid is related to the View, but the View will not be created in the Hidden mode.

My tips:
- Never convert your important documents into foreign (MS), obsolete (.xls), or badly descripted (.xlsx = OOXML Transitional) file formats. There is not (never was and never will be) 100% compatibility between the different fileformats.
- Do not use the Hidden mode...