Re: how to import excel file into django models?

3,456 views
Skip to first unread message

Artem Zinoviev

unread,
Jun 1, 2013, 11:09:07 AM6/1/13
to django...@googlegroups.com
Django models - it`s ORM to database, and exel is not database it`s only zipped xml file. You can convert your .xslt to .csv format and export it in db. 

суббота, 1 июня 2013 г., 12:21:33 UTC+3 пользователь Ali hallaji написал:

Vernon D. Cole

unread,
Jun 2, 2013, 3:44:53 PM6/2/13
to django...@googlegroups.com
I have used two methods -- one works only on Windows, the other is cross platform -- and you have said nothing about your application so it is hard to advise...

If you know Windows and SQL -- then use adobapi and open the spreadsheet as a table (see examples at http://sourceforge.net/projects/adodbapi) and read it using SQL SELECT commands.

If you are on Linux, then xlrd is your friend.  (Find it on pypi or http://www.python-excel.org/)  In my case, the spreadsheet was large, and the columns moved around from time to time, so I wrote a mini-ORM (xlrd_helper) to allow me to refer to the spreadsheet columns by name, rather than by number, and handle the idiosyncrasies of my application.  I have been working on this for several months, but my work is too application specific to publish.  (You probably do not need to do automatic spelling correction for the names of Nigerian villages.)  The python code which does the import is implemented as a set of manage.py command scripts.
--
Vernon Cole

On Saturday, June 1, 2013 3:21:33 AM UTC-6, Ali hallaji wrote:

Derek

unread,
Jun 3, 2013, 2:22:11 AM6/3/13
to django...@googlegroups.com
Just a small clarification - xlrd runs on both Windows and Linux and would be the recommended way to go here.

Otherwise I agree with Vernon - create a base xlrd_reader class, to handle generic reading and data checking, and then have model-specific routines that handle assignment of data to specific fields.  There is a ton of example code for xlrd on the web, and some with examples for Django.  My code works with forms that let the user specify which columns are being used for what, rather than a command-line approach.  How you handle this aspect depends on your use case...

Derek

Wim Feijen

unread,
Jun 3, 2013, 6:35:49 AM6/3/13
to django...@googlegroups.com
Hi,

Yesterday I did some research on this topic and I would like to recommend looking at examples on github, for example:
or
https://github.com/foreveryh/django-excel-import

But I didn't use any of them, because I decided to re-use my own code.

Wim
Reply all
Reply to author
Forward
0 new messages