|
#coding=utf-8import xlwtimport osimport shutil
path = '../sheet/'isExists = os.path.exists(path) # 判断目录是否存在if not isExists: # 如果目录不存在,新建目录
os.makedirs(path)
f = xlwt.Workbook() # 创建工作簿sheet1 = f.add_sheet(u'得分统计', cell_overwrite_ok=True)
mdict = {"monkey":{"writing":80,"reading":60,"speaking":70,"listening":60},"grape":{"writing":100,"reading":80,"speaking":70,"listening":60}}
sheet1.write(0,0,u'得分统计')
sheet1.write(1,0,u'书法得分')
sheet1.write(2,0,u'阅读得分')
sheet1.write(3,0,u'演讲得分')
sheet1.write(4,0,u'听力得分')
temp = ['writing','reading','speaking','listening']for pos,name in enumerate(mdict):
sheet1.write(0,pos+1,name) for p,v in enumerate(temp):
sheet1.write(p+1,pos+1,mdict[name][v])
sheet1.write(5,0,u'总分统计')for i in range(len(mdict)):
forstr = chr(65+i+1)+'2+'+chr(65+i+1)+'3+'+chr(65+i+1)+'4+'+chr(65+i+1)+'5'
print forstr
sheet1.write(5,i+1,xlwt.Formula(forstr))
f.save('得分统计')
shutil.move(u'得分统计', path)1234567891011121314151617181920212223242526272829303132333435363712345678910111213141516171819202122232425262728293031323334353637 |
|
|