# -*- coding: utf-8 -*-
__author__ = '10043467'
import xlwt
import xlrd
srcChenjifileName = 'cj-x班.xls'
srcChenjiSheetName = '所有成绩'
classIdIndexInSrc = 5 #第一列是从0开始
classNum =14 #班级数
dstFileNamePrefix =''
dstFileNamePostfix = '班'
# classidList = ['1班','2班','3班', '4班','5班','6班','7班','8班','9班','10班','11班','12班','13班','14班' ]
classidList = ['1','2','3', '4','5','6','7','8','9','10','11','12','13','14' ]
def isRowBelongClass(row, sheetSrc ,classid ):
xx = sheetSrc.cell_value(row,classIdIndexInSrc)
if isinstance(xx,float):
if int(xx) != classid:
return False
else:
return True
else :
if xx != classidList[classid -1] :
return False
else:
return True
def writeOneFile(filename, classid,sheetSrc):
f = xlwt.Workbook()
sheet1 = f.add_sheet('Sheet1',cell_overwrite_ok=True)
writeRow =0
for row in range(sheetSrc.nrows) :
# xx = sheetSrc.cell_value(row,1)
if isRowBelongClass(row,sheetSrc,classid) == False :
# if int(xx) != classid:
continue
for col in range(sheetSrc.ncols):
cellValue =sheetSrc.cell_value(row,col)
sheet1.write(writeRow,col,cellValue)
writeRow = writeRow +1
f.save(dstFileNamePrefix + filename + dstFileNamePostfix + ".xls")
wb = xlrd.open_workbook(filename=srcChenjifileName)#打开文件
cjSheet = wb.sheet_by_name(srcChenjiSheetName)#通过名字获取表格
for classid in range(1,classNum +1):
writeOneFile(str(classid), classid,cjSheet)