15

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.

7
  • 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, 2016 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, 2016 at 12:05
  • try this
    – Lety
    Feb 17, 2016 at 12:56
  • 1
    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. Feb 22, 2016 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, 2016 at 23:19

1 Answer 1

16

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
  • 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). Feb 22, 2016 at 23:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .