Skip to content

Commit

Permalink
- Change xlrd out with openpyxl
Browse files Browse the repository at this point in the history
  • Loading branch information
frankyrumple committed Apr 21, 2021
1 parent cd02b03 commit f11c29c
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 23 deletions.
5 changes: 3 additions & 2 deletions modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ ecdsa
isodate
pytube
pywinrm
xlrd
#xlrd - replaced by openpyxl
openpyxl
psutil
pycryptodome
urllib3
Expand All @@ -19,4 +20,4 @@ webvtt-py
langcodes
bs4
pdfkit
lxml
lxml
22 changes: 12 additions & 10 deletions web2py/applications/smc/modules/ednet/faculty.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
from gluon import *
from gluon import current

#import applications.smc.modules.xlrd
#from .. import xlrd
import xlrd
#import xlrd
# xlrd - quit supporting xlxs files
import openpyxl
import time

from ednet.util import Util
Expand All @@ -24,12 +24,14 @@ def ProcessExcelFile(excel_file):
out = DIV(Faculty.ClearImportQueue())
db = current.db # Grab the current db object

wbook = xlrd.open_workbook(excel_file)
for sheet in wbook.sheets():
out.append(DIV("Processing Sheet: " + sheet.name))
#wbook = xlrd.open_workbook(excel_file)
wbook = openpyxl.load_workbook(excel_file)
for sheet in wbook: # wbook.sheets():
out.append(DIV("Processing Sheet: " + sheet.title))
out.append(DIV("Processing Enabled Faculty."))
faculty_account_enabled = True # status 1 = active, 0 = inactive
for row in range(sheet.nrows):
#for row in range(sheet.nrows):
for row in sheet.iter_rows():
if Util.GetCellValue(sheet, row, 0).upper() == "USER ID":
out.append(DIV("Skipping Header Row."))
continue # should be header, skip this line
Expand All @@ -56,10 +58,10 @@ def ProcessExcelFile(excel_file):
import_classes = Util.GetCellValue(sheet, row, 3)
program = Util.GetCellValue(sheet, row, 4)
additional_fields = ""
if sheet.ncols > 5:
additional_fields = Util.GetJSONFromCellRange(sheet, row, 5, sheet.ncols)
if len(row) > 5:
additional_fields = Util.GetJSONFromCellRange(sheet, row, 5, len(row))

sheet_name = sheet.name
sheet_name = sheet.title
faculty_guid = None
account_enabled = faculty_account_enabled
account_added_on = time.strftime("%c")
Expand Down
23 changes: 13 additions & 10 deletions web2py/applications/smc/modules/ednet/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from gluon import *
from gluon import current

# import applications.smc.modules.xlrd
# from .. import xlrd
import xlrd

#import xlrd
# xlrd - quit supporting xlxs files
import openpyxl
import time
from datetime import timedelta

Expand All @@ -25,12 +26,14 @@ def ProcessExcelFile(excel_file):
out = DIV(Student.ClearImportQueue())
db = current.db # Grab the current db object

wbook = xlrd.open_workbook(excel_file)
for sheet in wbook.sheets():
out.append(DIV("Processing Sheet: " + sheet.name))
#wbook = xlrd.open_workbook(excel_file)
wbook = openpyxl.load_workbook(excel_file)
for sheet in wbook: # wbook.sheets():
out.append(DIV("Processing Sheet: " + sheet.title))
out.append(DIV("Processing Enabled Students."))
student_account_enabled = True # status 1 = active, 0 = inactive
for row in range(sheet.nrows):
#for row in range(sheet.nrows):
for row in sheet.iter_rows():
if Util.GetCellValue(sheet, row, 0).upper() == "USER ID":
out.append(DIV("Skipping Header Row."))
continue # should be header, skip this line
Expand All @@ -56,10 +59,10 @@ def ProcessExcelFile(excel_file):
import_classes = Util.GetCellValue(sheet, row, 3)
program = Util.GetCellValue(sheet, row, 4)
additional_fields = ""
if sheet.ncols > 5:
additional_fields = Util.GetJSONFromCellRange(sheet, row, 5, sheet.ncols)
if len(row) > 5:
additional_fields = Util.GetJSONFromCellRange(sheet, row, 5, len(row))

sheet_name = sheet.name
sheet_name = sheet.title
student_guid = None
account_enabled = student_account_enabled
account_added_on = time.strftime("%c")
Expand Down
20 changes: 19 additions & 1 deletion web2py/applications/smc/modules/ednet/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,25 @@ def GetModList(attr_list, mod_op=None):
def GetCellValue(sheet, row, col, default_val=""):
ret = default_val
try:
val = str(sheet.cell(row, col).value)
val = row[col].value #.value)
if val is None:
val = default_val
val = str(val)
# Strips off the .0 at the end of numbers
if val.endswith(".0"):
val = val[:-2]
ret = val
except:
# ret = "ERROR!!!"
pass
return ret

@staticmethod
def GetCellValue2(sheet, row, col, default_val=""):
# Old xlrd GetCellValue
ret = default_val
try:
val = str(sheet.cell(row, col)) #.value)
# Strips off the .0 at the end of numbers
if val.endswith(".0"):
val = val[:-2]
Expand Down

0 comments on commit f11c29c

Please sign in to comment.