-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (61 loc) · 2.25 KB
/
main.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
############## A script that adds a new row to a .numbers file. Used to keep track of the books I've read. ##########
#Importing used libraries
from openpyxl import load_workbook
from copy import copy
from openpyxl.styles import Font
from openpyxl.styles.borders import Border, Side, BORDER_THIN
date = input("On which date did you read the book?") #Get the date of book read from the user
book = input("Which book did you read?") #Get the book read from the user
author = input("Who is the author of the book?") #Get the author of the book from the user
category = input("Which category is the book?") #Get the category of the book from the user
type = input("Paper/E-book/Audiobook?") #Get the type of book read from the user
#Define which data you want to write on the new row
new_row_data = [
[date, book, author, category, type],
]
#Load the Excel Spreadsheet you want to work with.
wb = load_workbook("booksread.xlsx.xlsx")
#Select the first worksheet
ws = wb.worksheets[0]
#Append new rows
for row_data in new_row_data:
#Append row values
ws.append(row_data)
#Center all cells
for col in ws.columns:
for cell in col:
alignment_obj = copy(cell.alignment)
alignment_obj.horizontal = 'center'
alignment_obj.vertical = 'center'
cell.alignment = alignment_obj
#Define variable for bold font
bold = Font(bold=True)
#Define variable for thin border
thin_border = Border(
left=Side(border_style=BORDER_THIN, color='00000000'),
right=Side(border_style=BORDER_THIN, color='00000000'),
top=Side(border_style=BORDER_THIN, color='00000000'),
bottom=Side(border_style=BORDER_THIN, color='00000000')
)
# Bold text in column A
for cell in ws["A:A"]:
cell.font = bold
# Set border in column A
for cell in ws['A:A']:
cell.border = thin_border
# Set border in column B
for cell in ws['B:B']:
cell.border = thin_border
# Set border in column C
for cell in ws['C:C']:
cell.border = thin_border
# Set border in column D
for cell in ws['D:D']:
cell.border = thin_border
# Set border in column E
for cell in ws['E:E']:
cell.border = thin_border
# Save file
wb.save("booksread.xlsx")
# Print successful message to user
print("Congratulations on reading another book! It was saved successfully!")