Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I'm using Debian Linux and I want to convert a CSV file to an Excel XLS Spreadsheet file. The catdoc package includes the xls2csv command that converts from XLS to CSV. However it doesn't do the reverse.

Since I just have a CSV file, I don't care about formatting or anything like that. I'm not worried if it only generates a very simple XLS file, and doesn't support the fancy new versions. Just so long as it's an XLS spreadsheet.

share|improve this question
If you rename the file from foo.csv to foo.xls, when you put it on a Windows or Mac OS machine, Excel will open it quite happily. Same thing with html files renamed to foo.doc. –  Paul Tomblin Oct 13 '09 at 12:19
not really, I've just tested it (renamed a .csv into .xls) and, while it surely opens in Excel, the cell structure is messed up, or should I say, nonexistent - the cells in the leftmost column contain a line of the .csv file each, - the fields don't get separated. Not very useful –  shylent Oct 13 '09 at 12:21
Was the original .csv well-formatted? Try pasting a snippet of it into the question, as Paul's original suggestion has worked wonderfully for me in the past (Directive from management to generate Excel reports instead of CSV format - my solution was merely changing the extension of the output file and they were happy :) ) –  MikeyB Oct 13 '09 at 12:46
If a csv saved with a .xls extension doesn't work, you could try a tab separated text file. That's an easy conversion as long as there are no newlines or tabs in the data. –  rjmunro Apr 14 '11 at 11:59
I need this sort of conversion at my workplace because when I pass people CSV or TSV files, half the time Excel doesn't properly detect the column separator, or the fact that strings can be quoted, or whatever, and people get confused on what's going wrong and how to resolve it. It would be a smoother experience if I could just pass people a real XLS file I 100% knew Excel wouldn't have issues with. –  spiffytech May 15 '13 at 15:49

6 Answers 6

Why would you want to do that? Since you are not interested in adding or modifying data/metadata, you could just leave it as csv. CSV is associated with MS Excel by default, so whoever is going to open it, is going to get it opened in MS Excel.

If that does not work for you for some reason, keep in mind, that, as far as I know, you can generate a (sort of) valid xls file by using the following skeleton:

... ad inf

(I am serious)

share|improve this answer
+1 for being serious - it is! –  sybreon Oct 13 '09 at 13:03
In Office 2007, I get a warning "The file you are trying to open is in a different format than specified by the file extension. Verify that the file is not corrupted and from a trusted souce before opening the file. Do you want to open the file now?", which probaly isn't acceptable in many cases. –  rjmunro Apr 14 '11 at 12:18

Try using the ssconvert tool from "gnumeric" package. On Debian, install the package with sudo apt-get install gnumeric and then from the command-line, run:

ssconvert file.csv file.xls

This should do the job.

share|improve this answer
ssconvert does not keep your data in the same state as it was going in, and is as such not a utility that should be used unless you are absolutely certain that all fields are quoted etc. Example: a field with a value of 0330 will be converted to '330'. –  Christopher Apr 4 '13 at 8:05
Actually, when I now tested ssconvert again I found that it destroys your data, regardless of quoting, and as such is a tool that in my opinion can not be used at all. Sorry, but downvote from me. –  Christopher Apr 4 '13 at 8:18

There is a python based solution on Sourceforge called csv2xls which may fit the bill.

It does not appear to be maintained at the moment (last activity was over a year ago) but if it does what you need then that shouldn't matter too much.

share|improve this answer

Try using an Openoffice macro...

See for a start : How to convert Word -> PDF from the command line http://www.oooforum.org/forum/viewtopic.phtml?t=3772

share|improve this answer

There are indeed some problems with the filters from CSV and any form XLS or even openOffice. Like the: Record separator: , Line terminator: \n or ; String definition: " or the like.

If I get it correctly you want to do it on the command line within some scripts. This is exactly the same problem I have right now: from DATA in csv format, present it to the customer in XLS format.

I have found this post: https://forum.openoffice.org/en/forum/viewtopic.php?f=5&t=39844

But I am not totally satisfied. They might be an option.

Indeed if you have some sort of openOffice installed you can try to play with some info from: http://ask.libreoffice.org/en/question/2641/convert-to-command-line-parameter/

On my shell I typed:

soffice --help

And part of the output is:

--convert-to output_file_extension[:output_filter_name] [-outdir ouput_dir] files
      Batch convert files.
      If -outdir is not specified then current working dir is used as output_dir.
      Eg. -convert-to pdf *.doc
          -convert-to pdf:writer_pdf_Export -outdir /home/user *.doc
share|improve this answer

I would argue that a .CSV file is already an Excel file with the features you want. There's only one annoyance to avoid and you are all set. If you really want to convert it to .XLS, have Excel do it later. But really there's no need to do so, given the description you provide.

share|improve this answer

Your Answer


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.