ODS conversion to xls/xlsx problem

The Application Programming Interface and the OASIS Open Document Format

ODS conversion to xls/xlsx problem

Postby ototbeli » Tue Jul 24, 2018 7:19 pm

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

}
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
ototbeli
 
Posts: 2
Joined: Tue Jul 24, 2018 7:04 pm

Re: ODS conversion to xls/xlsx problem

Postby Zizi64 » Tue Jul 24, 2018 7:27 pm

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; LO4.4.7, LO6.1.5 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.0 and AOO4.1.5
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.
User avatar
Zizi64
Volunteer
 
Posts: 7704
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: ODS conversion to xls/xlsx problem

Postby John_Ha » Tue Jul 24, 2018 8:36 pm

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.
AOO 4.1.6, Windows 7 Home 64 bit

See the Writer Manual, the Writer FAQ, the Writer Tutorials and the Writer guide.

Remember: Always save your Writer files as .odt files. - see here for the many reasons why.
John_Ha
Volunteer
 
Posts: 6343
Joined: Fri Sep 18, 2009 5:51 pm
Location: UK

Re: ODS conversion to xls/xlsx problem

Postby ototbeli » Tue Jul 24, 2018 11:03 pm

#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
ototbeli
 
Posts: 2
Joined: Tue Jul 24, 2018 7:04 pm

Re: ODS conversion to xls/xlsx problem

Postby Zizi64 » Wed Jul 25, 2018 6:16 am

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; LO4.4.7, LO6.1.5 on Win7-10 x64Prof.
PortableApps, winPenPack: LO3.3.0-6.2.0 and AOO4.1.5
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.
User avatar
Zizi64
Volunteer
 
Posts: 7704
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 1 guest