开发者

How do I convert excel file with n worksheets into n csv files?

开发者 https://www.devze.com 2023-04-11 09:17 出处:网络
Is there a w开发者_如何学Goay to convert the worksheets in an excel file into a number of csv files? Yes.There is.

Is there a w开发者_如何学Goay to convert the worksheets in an excel file into a number of csv files?


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/.


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.)

0

精彩评论

暂无评论...
验证码 换一张
取 消