14

I need to convert ".xlsx" file to ".xls" using shell command.

At my work we are currently using xlsx2csv command but now requirement has been changed and we need to convert all ".xlsx" files to ".xls" files for further calculation.

For that, Some guy at my work has developed one command that can convert ".xlsx" to ".xls" but, that is applicable for only one sheet..

We have multiple sheets in one file.

Thanks in advance....

20

If you install LibreOffice, you can use the following command:

libreoffice --headless --convert-to xls myfile.xlsx

or just:

libreoffice --convert-to xls myfile.xlsx

in recent version (>= 4.5) where --convert-to implies --headless.

This will create myfile.xls, and keep the original myfile.xlsx—so you’ll probably need to do a cleanup after you've validated the conversion is successful.

  • This option is very good, but i think there is one problem, it opens libreoffice instance and then converts it to ".xls" file. Is there any other option that will not open libreoffice and still able to convert to ".xls" file ? can you help me with this ? @forquare – Prem Joshi Mar 27 '17 at 8:03
  • 1
    @PremJoshi Man page says: "[--convert-to] implies --headless." so the GUI is not opened. However, when you launch it for the first time after boot, it may show a splash screen or something like that while it registers services (depending on your desktop). – lgeorget Mar 27 '17 at 8:09
  • 1
    @Igeorget ! option "--headless" worked for me ! this was exact answer for my question. – Prem Joshi Mar 27 '17 at 8:17
  • 3
    The commit that made --convert-to imply --headless is gerrit.libreoffice.org/… (version 4.4). In previous versions, both options have to be passed. – lgeorget Mar 27 '17 at 8:51
  • 1
    Be aware of the xls format 65535 row limit, as this command does not print any warning message if the xlsx file exceeds that limit (it will output a 65535 row file which does not correspond to the original, with no warning) – golimar Aug 26 '19 at 13:31
6

you can also try ssconvert the companion converter tool of gnumeric

ssconvert in.xlsx out.xls

(as usually, see man ssconvert)

For normal cases, this is fine. If the input file is very advanced in both (libreoffice and gnumeric)-based converters, some details may be lost.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.