[Django]-Getting data from an Excel sheet

6👍

Have a look at the xlrd package, which allows you to read Excel files in Python. Once you’ve read the data you can do whatever you want with it, including saving it to the database.

For a basic usage example, look at http://scienceoss.com/read-excel-files-from-python/

3👍

Use django-batchimport http://code.google.com/p/django-batchimport/ It provides a very simple way to upload data in Excel sheets to your Django models. I have used it in a couple of projects. It can be integrated very easily into your existing Django project.

Read the documentation on the project page to know how to use it.

It is built on XLRD.

2👍

Have a look at the presentation “Excel & Python” that Chris Withers gave at PyCon US:

“This lightning talk explains that you don’t need to use COM or be on Windows to read and write native Excel files.”

http://www.simplistix.co.uk/presentations/python_excel_09/excel-lightning.pdf

0👍

Programatically or manually? If manualy then just save the excel as a CSV (with csv or txt extension) and import into Postgresql using

copy the_data from '/path/to/csv/MYFILE.txt' DELIMITERS ',' CSV;

0👍

As I remember of this.
The best way is to save this sheet as plain text ( CSV or something )
And then load with some custom SQL script.
http://www.postgresql.org/docs/8.3/static/populate.html

0👍

Or have a look at SQLAlchemy if you’re going to write some kind of script to help you with that.(http://www.sqlalchemy.org/)

0👍

If you want to use COM to interface excel (i.e. you are running on a Windows machine), see “Migrating Excel data to SQLite” – http://www.saltycrane.com/blog/2007/11/migrating-excel-to-sqlite-using-python/

👤wisty

0👍

I built django-batchimport on top of xlrd which is AMAZING. The only issues I had were with getting data into Django. Had nothing to do with any limitations of xlrd. It rocks. John’s work is incredible.

Note that I’ve actually done some update work to django-batchimport and just released. Take a look: http://code.google.com/p/django-batchimport/

-1👍

Just started using XLRD and it looks very easy and simple to use.

Beware that it does not support Excel 2007 yet, so keep in mind to save your excel at 2003 format.

👤OritK

Leave a comment