1

Is there a way to convert the worksheets in an excel file into a number of csv files?

Mandeep
  • 385
  • 1
  • 3
  • 12
  • Don't know the exact answer but this can be a start - http://www.python-excel.org/ – ronakg Oct 06 '11 at 13:50
  • Search is a good start, also: http://stackoverflow.com/questions/1747501/getting-data-from-an-excel-sheet and http://stackoverflow.com/questions/1459788/get-the-inputs-from-excel-and-use-those-inputs-in-python-script. – S.Lott Oct 06 '11 at 14:00

2 Answers2

4

Yes. There is.

  1. xlrd will allow you to read a spreadsheet. http://pypi.python.org/pypi/xlrd

  2. csv will allow you to write CSV files. http://docs.python.org/library/csv.html

This happened to me so often, that I uploaded a spreadsheet reader library to SourceForge. http://sourceforge.net/projects/stingrayreader/.

S.Lott
  • 384,516
  • 81
  • 508
  • 779
0

xlrd is fine but won't handle the newer excel format (xlsx). (yet)

One alternative, on a windows machine with excel installed, is to use the Python/COM interface to drive excel.

A similar approach (but not reliant on platform and vendor) is to use Open Office to read the spreadsheet via its python api. An article with python script is: Convert Spreadsheets to CSV files with Python and PyUno

One gotcha: if you use the native 'save as', either of excel or OO, to do the conversion, you get the data as formatted in the sheet. (This is the approach used by the above OO solution and the usual excel/COM solution.) So numeric data, for example, will be rounded to the number of decimal places that excel would display. (For dates, this is usually a good thing, since you get the formatted date string, rather than the underlying numerical value.)

c-urchin
  • 4,344
  • 6
  • 28
  • 30