Is there a w开发者_如何学Goay to convert the worksheets in an excel file into a number of csv files?
Yes. There is.
xlrd
will allow you to read a spreadsheet. http://pypi.python.org/pypi/xlrdcsv
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/.
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.)
精彩评论