Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
    
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 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 at 12:05
    
try this – Lety Feb 17 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 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 at 23:19
up vote 10 down vote accepted

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 
share|improve this answer
    
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 at 23:08
    
@PaddyLandau thanks for your note – Maythux Feb 23 at 7:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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