I wanna parse excel and put data in the model(User). views.py is
#coding:utf-8
from django.shortcuts import render
import xlrd
from .models import User
book = xlrd.open_workbook('../data/data.xlsx')
sheet = book.sheet_by_index(1)
for row_index in range(sheet.nrows):
rows = sheet.row(row_index)
print(rows[1])
for row in rows:
user = User(user_id=row[1], name_id=row[2], age=row[3],
name=rows[4])
user.save()
Excel is excel
I do not want to put data of row whose user_id & name column is empty.In this case,I do not want to put data of line 5 & 6 .But now, my code is to put all excel data to User model.I cannot understand how to extract excel data and put to model.What should I do to do so?I thought if content of list is empty, the data should be skipped.But list is not separate each content, for example [1,1,40,Tom]
can be counted 1 list.