Esempio n. 1
0
def pop_all(request):

    from openpyxl import load_workbook

    wb = load_workbook( 'media/'+'docs/Book.xlsx', use_iterators=True)
    sheet = wb.worksheets[0]
    row_count = sheet.max_row
    #column_count = sheet.max_column
    if len(Words.objects.all())==0:
        id=1
    else:
        id=len(Words.objects.all())+1
    #populates words
    count=1
    for i in range(1,row_count-1):
        if sheet.cell(row=i, column = 1).value!=None:
            count+=1

    for i in range(1,row_count-1):
        if sheet.cell(row=i, column = 1).value!=None:
            word=sheet.cell(row=i , column = 1).value
            pos=sheet.cell(row=i , column = 2).value
            tran=sheet.cell(row=i , column = 4).value
            w1=Words(id=id,word=word,pos=pos,tran=tran)
            w1.save()
            id+=1

    #population of colocations

    if len(Colocs.objects.all())==0:
        c_id=0 # for initial
    else:
        c_id=len(Words.objects.all())-count+1 # for adding

    #populates colocations
    for i in range(1,row_count-1):
        if sheet.cell(row=i, column=1).value!=None:
            c_id+=1
        else:
            coloc=sheet.cell(row=i,column=3).value
            c_tran=sheet.cell(row=i , column = 4).value
            c1=Colocs(c_id=c_id, coloc=coloc, c_tran=c_tran)
            c1.save()
    return JsonResponse({'message':'All is populated, refresh the page'})
Esempio n. 2
0
import os
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'exceldb.settings')
import django
django.setup()
from exdb.models import Words
from openpyxl import load_workbook

wb = load_workbook('static/docs/Book.xlsx', use_iterators=True)
sheet = wb.worksheets[0]
row_count = sheet.max_row
column_count = sheet.max_column
if len(Words.objects.all())==0:
    id=1
else:
    id=len(Words.objects.all())+1
print id
print row_count
#populates words
for i in range(1,row_count-1):
    if sheet.cell(row=i, column = 1).value!=None:
        word=sheet.cell(row=i , column = 1).value
        pos=sheet.cell(row=i , column = 2).value
        tran=sheet.cell(row=i , column = 4).value
        w1=Words(id=id,word=word,pos=pos,tran=tran)
        w1.save()
        id+=1