Search code examples
djangoexceldjango-modelsdjango-formsxlrd

How to parse the values in excel file and store it in database using django


1.I am working in a project,were i am storing student name and phone number in a spreadsheet(.xls).

2.I am using django framework,in my app which have a button namely import from spreadsheet.So if i press this button i should able to upload a .xls file,and by pressing the save button the details namely name and phone number should be saved in database using parsing.

So how to achieve this.

My models.py is

class Contactlist
    report = models.ForeignKey(Report, null=True)
    cname = models.CharField(max_length=100)
    pnumber = models.IntegerField()  

Thanks


Solution

  • Use xlrd and write a method in your class that receives an Excel spreadsheet as input and imports the data. This site gives an example of how to use it in general, here is an example of using it in Django to accomplish this task.

    You could also try the existing django-excel-import module.