Server Fault is a question and answer site for system and network administrators. 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

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

closed as off-topic by masegaloeh, Nathan C, Hyppy, mdpc, dawud Apr 17 '15 at 22:22

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions on Server Fault must be about managing information technology systems in a business environment. Home and end-user computing questions may be asked on Super User, and questions about development, testing and development tools may be asked on Stack Overflow." – masegaloeh, Nathan C, Hyppy, mdpc, dawud
If this question can be reworded to fit the rules in the help center, please edit the 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

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
You wouldn't want to do this because Excel is terrible at interpreting and formatting CSV files. e.g. It will automatically interpret a numeric text as an integer, even if it's quoted or 30 characters long, causing it to render in scientific notation. – Cerin Feb 20 '15 at 19:30

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
Yeah, ssconvert is useless for any serious work. I had been using ssconvert a lot until I realized it screws up formatting for any text containing numeric characters. i.e. ditto what Christoper says. This really sucks because otherwise ssconvert is painless. – Cerin Feb 20 '15 at 19:33

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

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:

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:

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 write a little code to directly output a simple version of the Excel 2002 XML format:

XML Spreadsheet

Though the intended file extension for this format is .xml, the program also correctly handles XML files with .xls extension. This feature is widely used by third-party applications (e.g. MySQL Query Browser) to offer "export to Excel" capabilities without implementing binary file format. The following example will be correctly opened by Excel if saved either as Book1.xml or Book1.xls:

<?xml version="1.0"?>
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
 <Worksheet ss:Name="Sheet1">
  <Table ss:ExpandedColumnCount="2" ss:ExpandedRowCount="2" x:FullColumns="1" x:FullRows="1">
    <Cell><Data ss:Type="String">Name</Data></Cell>
    <Cell><Data ss:Type="String">Example</Data></Cell>
    <Cell><Data ss:Type="String">Value</Data></Cell>
    <Cell><Data ss:Type="Number">123</Data></Cell>

Alternately, if that didn't provide enough features, I'd directly implement minimal .xlsx output. It is a zip file with XML files which should be tractable compared to the old binary formats.

share|improve this answer

There is a software called csv2xls (written in C++), that should do exactly what you want (not to be confused with the Python2 implementation mentioned in another answer).

The last commit was 2 months ago and from the looks of it, the software appears to be stable.

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

There is effectively a need to convert CSV to Excel, when you are sending files to Users who do not want to Convert themselves CSV files to Excel. There is also the way within Excel to open a CSV file and save it to an Excel formatted-file. But we want to avoid this extra step for Users. I have found, to my frustration, that , apart from PowerShell scripting , there is no reliable product in the market to do the conversion from a command-line, respecting column separators, en-of-line, headers and parameters you might want to add.

share|improve this answer
PowerShell? This is Sparta... ergh, sorry, Linux! – Deer Hunter Apr 17 '15 at 11:49

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