1

I have an excel file, in which there are emails of users in column F. I would like to get the emails in each row and import into a django database. However; as I am very new to Django, I do not understand how to do it. Here is what I tried:

import openpyxl
from ms.common.models import User, Participant, Question, Answer


wb = openpyxl.load_workbook('list.xlsx')
ws = wb.get_sheet_names()
for row in ws.iter_rows('F{}:F{}'.format(ws.min_row,ws.max_row)):
    for cell in row:
        print cell.value

 #create email
    participant, created = Participant.objects.get_or_create(mail=user.username)
Brown Bear
  • 19,655
  • 10
  • 58
  • 76
oezlem
  • 237
  • 2
  • 12
  • 1
    Possible duplicate of [Read specific columns from a csv file with csv module?](https://stackoverflow.com/questions/16503560/read-specific-columns-from-a-csv-file-with-csv-module) – Sam Hazleton Aug 24 '17 at 12:43
  • Ok i changed the first line and now i can get all the email addresses, how can I add these to the participant model? participant, created = Participant.objects.get_or_create(mail=user.username) is this okey° – oezlem Aug 24 '17 at 13:28
  • 1
    what about `participant = Participant.objects.create(mail=cell.value)` ? – alfonso.kim Aug 24 '17 at 14:14

0 Answers0