I have one excel file which have candidate details such as name,position,place,email and date. And I am importing that file into my project for bulk import, but it is gives error while importing date column even if I stored date in excel in proper format. I am doing it in django python
Here is my code of views.py
fs = FileSystemStorage()
filedata = fs.save("ImportDB.xls", myfile)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
filepath = BASE_DIR + "\media\ImportDB.xls"
book = xlrd.open_workbook(filepath)
sheet = book.sheet_by_name("Sheet1")
database = MySQLdb.connect(host="localhost", user="root", passwd="1234", db="rms")
cursor = database.cursor()
query = """INSERT INTO candidate_details (CandidateName, Position, PhoneNumber, Mobile,EmailID, Place,CreatedDate) VALUES (%s, %s, %s, %s, %s,%s,%s)"""
for r in range(1, sheet.nrows):
CandidateName = sheet.cell(r, 1).value
Position = sheet.cell(r, 2).value
PhoneNumber = sheet.cell(r, 3).value
Mobile = sheet.cell(r, 4).value
EmailID = sheet.cell(r, 5).value
Place = sheet.cell(r, 6).value
CreatedDate = sheet.cell(r, 7).value
values = (CandidateName, Position, PhoneNumber, Mobile , EmailID, Place,CreatedDate)
cursor.execute(query, values)
cursor.close()
database.commit()
database.close()
fs.delete(filedata)
I am attaching screenshot of my excel file which I am importing and error page.
Phutos – Google Drive[
^]
What I have tried:
I have tried to convert it but still not working.