Advertisement
AppajiC

Untitled

Nov 14th, 2022
893
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.91 KB | None | 0 0
  1. from openpyxl import load_workbook, Workbook
  2.  
  3.  
  4. defaulters = []
  5. MIN_PERCENT = 70
  6.  
  7. wb = load_workbook(filename="input.xlsx")
  8. sheet = wb.active
  9. total_days = sheet.max_column - 2
  10.  
  11. for row in sheet.iter_rows(min_row=2):
  12.     attendance = sum([i.value for i in row[2:]])
  13.     if attendance < total_days * (MIN_PERCENT / 100):
  14.         defaulters.append(
  15.             [
  16.                 row[0].value,
  17.                 row[1].value,
  18.                 attendance,
  19.                 total_days,
  20.                 round((attendance / total_days) * 100, 2),
  21.             ]
  22.         )
  23.  
  24. wb = Workbook()
  25. sheet = wb.active
  26. headers = ["Roll", "Name", "Count", "Total", "perc"]
  27. for i, h in enumerate(headers, start=1):
  28.     sheet.cell(row=1, column=i).value = h
  29.  
  30. for i, row in enumerate(defaulters, start=2):
  31.     for j, col in enumerate(row, start=1):
  32.         sheet.cell(row=i, column=j).value = col
  33.  
  34. wb.save("defaulter.xlsx")
  35.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement