0

I'm Vice Wing Commander at the Air Force Detachment I go to here at college. One responsibility of my job is taking attendance. Within the wing there are four squadrons. Each squadron turns in attendance every week and I have to transfer the attendance recorded to an attendance tracker written in an Excel worksheet. As you can imagine, this is very tedious work. Since I know some programming (I'm a senior comp sci major), I decided to write a python script that would automatically transfer the attendance. I'm using xlrd/xlwt/xlutils but I'm running into some issues. Basically what I'm trying to do is create key value pairs using the cadet's name and their attendance status taken from one worksheet, and export the values to the attendance tracker. Maybe I'm going about this wrong, but it's not working out so well. So far, the only thing I've been able to do is import the attendance from one file into key value pairs within the program. The issues come when I try to export these values. I've posted one question here which was resolved and an unanswered one here relating to my little project. Below is the code I have so far:

from xlrd import open_workbook

wb = open_workbook('week1/AFROTC SP13 Eagles Sqaudron Weekly Attendance.xls')

LLab = {}
PT = {}

for s in wb.sheets():
    if s.name == "LLab":
        for row in range(s.nrows):
            values = []
            for col in range(s.ncols):
                values.append(s.cell(row,col).value)
            if values[1] == "0" or values[1] == "1":
                LLab[values[0]]=int(values[1])

    elif s.name == "PT":
        for row in range(s.nrows):
            values = []
            for col in range(s.ncols):
                if s.cell(row,col).value != "PT #1" and s.cell(row,col).value != "PT #2":
                    values.append(s.cell(row,col).value)
            if len(values) == 3:
                PT[values[0]]=[int(values[1]), int(values[2])]

print "LLab"
for key in LLab:
    print key,
    print LLab[key]

print
print

print "PT"
for key in PT:
    print key,
    print PT[key][0],
    print PT[key][1]

It is only importing attendance from one file for now (there are four, one for each squadron).

Community
  • 1
  • 1
Dave
  • 503
  • 1
  • 8
  • 21
  • Basically I'm just wondering if I'm going about it the right way, and if not if there are any suggestions that anyone could give. – Dave Jan 28 '13 at 16:18
  • 2
    You say you're using "xlrd/xlwt/xlutils" but you've only got `xlrd` here. Judging by your [other question](http://stackoverflow.com/questions/14554770/writing-to-existing-workbook), you probably want to look into `xlutils.copy`. You will most likely have to copy the attendance tracker (in the `xlutils` sense of copy!), write your new values (in the `xlwt` sense of write), and then save (overwriting) the attendance tracker. Also, if you haven't already, check out the [tutorial](http://www.simplistix.co.uk/presentations/python-excel.pdf) (de facto manual) for all three packages. – John Y Feb 13 '13 at 23:07

0 Answers0