13

Is there a way, ideally using the command line, to convert multiple .csv files to one multi-sheet .xls spreadsheet?

If there isn't a cli solution, it'd be good to know if there's an API that works in, ideally, awk or pascal, but, failing that, in pretty-well anything.

  • ssconvert, mentioned by Maythux, is a companion command to Gnumeric, which will be installed by default on an Ubuntu Desktop system, but not on a server version. – Arronical Feb 17 '16 at 10:09
  • Given the fact Excel will load CSV in an .xls file you could simply do: cat *.csv > file.xls – ash Feb 17 '16 at 12:05
  • try this – Lety Feb 17 '16 at 12:56
  • ssconvert does the trick, perfectly. What I needed was to have each .csv file in a separate sheet. Using cat doesn't achieve that. ssconvert does. – Peter Brooks Feb 22 '16 at 6:37
  • @ash csv and xls are different formats, catting a bunch of csvs to a file and renaming it xls wont work at all, since csvs dont support multiple sheets so it would just make one long csv, and also since csv is a plaintext format whereas xls is a binary format – chiliNUT Feb 23 '16 at 23:19
15

You can use the command ssconvert.

ssconvert example.csv example.xls

To do it for multiple files you have to make a bash loop over csv files and do the job. Here a hint:

for i in *.csv; do ssconvert "$i" "${i%.*}".xls; done

EDIT:

To convert and merge into one single xls file also you still can use ssconvert.

ssconvert --merge-to=output.xls file1.csv file2.csv ....

or easily

ssconvert --merge-to=output.xls *.csv 
  • 1
    It is vital to quote the variables, as "$i" "${i%.*}".xls, otherwise any file name containing a space will break the command (and potentially overwrite an unrelated file). – Paddy Landau Feb 22 '16 at 23:08

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.