-
Notifications
You must be signed in to change notification settings - Fork 0
/
spreadsheet.py
53 lines (44 loc) · 1.47 KB
/
spreadsheet.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from openpyxl import Workbook, load_workbook
from openpyxl.cell import Cell
from openpyxl.utils import get_column_letter, column_index_from_string
import time
import os
import sqlite3
#database connection
conn = sqlite3.connect('Face-DataBase')
c = conn.cursor()
#get current date
currentDate = time.strftime("%d_%m_%y")
#create a workbook and add a worksheet
if(os.path.exists('./reports.xlsx')):
wb = load_workbook("reports.xlsx")
sheet = wb['Cse16']
# sheet[ord() + '1']
for col_index in range(1, 100):
col = get_column_letter(col_index)
if sheet.cell(row = 1, column = 1).value is None:
col2 = get_column_letter(col_index - 1)
# print sheet.cell('%s%s'% (col2, 1)).value
if sheet.cell('%s%s' % (col2,1)).value != currentDate:
sheet['%s%s' % (col,1)] = currentDate
break
#saving the file
wb.save(filename = "reports.xlsx")
else:
wb = Workbook()
dest_filename = 'reports.xlsx'
c.execute("SELECT * FROM Students ORDER BY Roll ASC")
#creating worksheet and giving names to column
ws1 = wb.active
ws1.title = "Cse16"
ws1.append(('Roll Number', 'Name', currentDate))
ws1.append(('', '', ''))
#entering students information from database
while True:
a = c.fetchone()
if a == None:
break
else:
ws1.append((a[2], a[1]))
#saving the file
wb.save(filename = dest_filename)