Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am looking for a way to quickly convert a directory of .csv files into the .xls or .xlsx format (would be nice if I could do either/or).

Is there an easy way to do this or do I need to install a third party program?

share|improve this question
Not sure why you would need to do so. csv's open well in excel. anyone needing to interact could just open without issue. –  Jody Jun 24 '11 at 0:28
You are right Excel opens csv and xls/xlsx just fine. Other programs, however, do not. =) –  mindless.panda Jun 24 '11 at 0:37
So what program are you looking to use this in? –  Kirk Jun 24 '11 at 2:21

3 Answers 3

up vote 6 down vote accepted

Assuming you like and have Python (for some reason), you could use this script I whipped up:

import os
import glob
import csv
import xlwt # from http://www.python-excel.org/

for csvfile in glob.glob(os.path.join('.', '*.csv')):
    wb = xlwt.Workbook()
    ws = wb.add_sheet('data')
    with open(csvfile, 'rb') as f:
        reader = csv.reader(f)
        for r, row in enumerate(reader):
            for c, val in enumerate(row):
                ws.write(r, c, val)
    wb.save(csvfile + '.xls')

Ran in the directory with all the CSV files, it will convert them all and slap a ".xls" onto the end.

For Excel 2007+ (xlsx files) supporting up to about 1 Mrows:

import os
import glob
import csv
import openpyxl # from https://pythonhosted.org/openpyxl/ or PyPI (e.g. via pip)

for csvfile in glob.glob(os.path.join('.', '*.csv')):
    wb = openpyxl.Workbook()
    ws = wb.active
    with open(csvfile, 'rb') as f:
        reader = csv.reader(f)
        for r, row in enumerate(reader, start=1):
            for c, val in enumerate(row, start=1):
                ws.cell(row=r, column=c).value = val
    wb.save(csvfile + '.xlsx')
share|improve this answer
@DavidPostill please don't approve edit suggestions that are merely comments. –  Nick T Sep 25 '14 at 16:45

Here is a perl script that supposedly does it, but it does seem like a lot of work to do something that is already built into Excel.

share|improve this answer

There is a lot left unsaid in your question.

Assuming that your CVS files are in a directory structure similar to


and you want to end up with


I can think of three routes to go depending on the ratio of upfront work to clean-up work you are willing to do.

  1. No Precoding: Use Windows Explorer to navigate to the CSV files use whatever method works best to select the files to be converted (lasso, ctrl+a, ctrl+click, shift+click) then right click one of the selected files and click on Open. This will open all the files in Excel. Then for each file you can select "File" and "Save as" and finally choose the new file format you want it saved to.
  2. A Simple Batch File: That batch file could use wild cards and/or a for each loop structure to open each of the CSV files for you and then you could manually process them as before.
  3. Create a VBA program within an Excel Spreadsheet: VBA could automatically opens each CSV file and then saves it to an Excel format. You could even add a simple message box that offers a choice of either xls or xlsx as each file is opened.

Note that I haven't written any code to do these things (yet) I am just offering ideas for a starting point. Perhaps if you could give more details about what you want you could get more detailed explanations for how to handle approach from me or another forum member.

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.