ODS conversion to xls/xlsx problem

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
ototbeli
Posts: 2
Joined: Tue Jul 24, 2018 7:04 pm

ODS conversion to xls/xlsx problem

Post 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

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);

}
Last edited by robleyd on Wed Jul 25, 2018 8:38 am, edited 1 time in total.
Reason: Added Code tags
openoffice 4.1.2
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: ODS conversion to xls/xlsx problem

Post 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?
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
John_Ha
Volunteer
Posts: 9583
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: ODS conversion to xls/xlsx problem

Post 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.
LO 6.4.4.2, Windows 10 Home 64 bit

See the Writer Guide, the Writer FAQ, the Writer Tutorials and Writer for students.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
ototbeli
Posts: 2
Joined: Tue Jul 24, 2018 7:04 pm

Re: ODS conversion to xls/xlsx problem

Post by ototbeli »

#Zizi64 yes i'm using LibreOffice for xlsx, but OpenOffice also has the same impact when converting ods to xls format.
openoffice 4.1.2
User avatar
Zizi64
Volunteer
Posts: 11352
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: ODS conversion to xls/xlsx problem

Post 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...
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
Post Reply