本文整理汇总了Python中xlrd.cellname函数的典型用法代码示例。如果您正苦于以下问题:Python cellname函数的具体用法?Python cellname怎么用?Python cellname使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cellname函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: writeHtml
def writeHtml(w_filename, r_filename,sheetname):
book = open_workbook(r_filename)
sheet = book.sheet_by_name(sheetname)
print sheet.nrows, 'rows and ' , sheet.ncols , 'cols in this sheet.'
for col_index in range(sheet.ncols):
print cellname(0,col_index),'-',
print sheet.cell(0,col_index).value
print
f = open(w_filename,'w')
f.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>')
f.write('<table>')
for row_index in range(sheet.nrows):
f.write('<tr>')
for col_index in range(sheet.ncols):
f.write('<td>')
if sheet.cell(row_index,col_index).ctype == 1:
value = sheet.cell(row_index,col_index).value.encode('UTF-8')
else:
value = ''
print value
# f.write(value)
f.write('</td>')
f.write('</tr>')
f.write('</table>')
f.close()
开发者ID:ilovefreeday,项目名称:ETL-by-python,代码行数:29,代码来源:excel_all.py
示例2: data_amend_report
def data_amend_report(workbook, gl, ibm, nc_sp, pvs_sp, fm_sp):
# Sheet 1
sheet = workbook.get_sheet(0)
# Download hyperlink:
sheet.write(1, 0, Formula('HYPERLINK("{}")'.format(settings.IBM_DATA_AMEND_URI)))
# Padded zeroes number format
pad2, pad3, pad4 = XFStyle(), XFStyle(), XFStyle()
pad2.num_format_str = '00'
pad3.num_format_str = '000'
pad4.num_format_str = '0000'
current_row = 3
code_id = ''
for row, data in enumerate(gl, current_row):
# Only insert GLPivDownload objects with a matching IBMData object.
if ibm.filter(ibmIdentifier=data.codeID).exists():
# We have to aggregate all the GLPivotDownload objects with
# matching codeID values, and insert one row with total
# ytdActual and fyBudget values.
if code_id != data.codeID: # Reached the next codeID value.
current_row += 1 # Advance one row.
code_id = data.codeID
i = ibm.get(ibmIdentifier=data.codeID)
sheet.write(current_row, 0, data.codeID)
sheet.write(current_row, 1, int(data.costCentre), pad3)
sheet.write(current_row, 2, data.account, pad2)
sheet.write(current_row, 3, data.service, pad2)
sheet.write(current_row, 4, data.activity, pad3)
try:
sheet.write(current_row, 5, int(data.project), pad4)
except ValueError:
sheet.write(current_row, 5, data.project, pad4)
try:
sheet.write(current_row, 6, int(data.job), pad3)
except ValueError:
sheet.write(current_row, 6, data.job, pad3)
sheet.write(current_row, 7, data.jobName)
sheet.write(current_row, 8, data.activityName)
sheet.write(current_row, 9, data.projNameNo)
sheet.write(current_row, 10, i.budgetArea)
sheet.write(current_row, 11, i.projectSponsor)
sheet.write(current_row, 14, i.regionalSpecificInfo)
sheet.write(current_row, 15, i.servicePriorityID)
sheet.write(current_row, 18, i.annualWPInfo)
sheet.write(current_row, 19, data.mPRACategory)
ytd = gl.filter(codeID=code_id).aggregate(Sum('ytdActual'))
fy = gl.filter(codeID=code_id).aggregate(Sum('fybudget'))
sheet.write(current_row, 20, ytd['ytdActual__sum'])
sheet.write(current_row, 21, fy['fybudget__sum'])
# Insert the footer row formulae and '#END OF INPUT'
sheet.write(current_row+2, 0, '#END OF INPUT')
sheet.write(current_row+2, 20, Formula('SUM({}:{})'.format(cellname(4, 20), cellname(current_row, 20))))
sheet.write(current_row+2, 21, Formula('SUM({}:{})'.format(cellname(4, 21), cellname(current_row, 21))))
# Sheet 2 - Service priority checkboxes.
sheet = workbook.get_sheet(1)
write_service_priorities(sheet, nc_sp, pvs_sp, fm_sp)
开发者ID:parksandwildlife,项目名称:ibms,代码行数:60,代码来源:report.py
示例3: validate
def validate(s, isNx):
x = 11
y = 4
if isNx == False:
for i in range(x, s.nrows):
for j in range(4, s.ncols):
try:
value = unicode(s.cell(i, j).value)
value = value.replace(' ', '')
value = value.replace(',', '.')
if len(value) != 0:
value1 = float(value)
if (value1 < 0) | (value1 > 10):
return u'Điểm ở ô ' + cellname(i, j) + u' không nằm trong [0,10] '
except Exception as e:
# print "aaaaaa"
return u'Điểm ở ô ' + cellname(i, j) + u' không hợp lệ'
else:
for i in range(x, s.nrows):
for j in range(4, s.ncols):
try:
value = unicode(s.cell(i, j).value)
value = value.replace(' ', '').lower()
if len(value) != 0:
if (value != u'đ') & (value != u'cđ') & (value != u'd') & (value != u'cd'):
return u'Lỗi ở ô ' + cellname(i, j) + u'. Chỉ dùng các kí tự sau để cho điểm D,Đ,CD,CĐ.'
except Exception as e:
# print e
return u'Lỗi ở ô ' + cellname(i, j) + u'. Chỉ dùng các kí tự sau để cho điểm D,Đ,CD,CĐ.'
return ''
开发者ID:tranvictor,项目名称:truongnha,代码行数:33,代码来源:importMark.py
示例4: excelToArray
def excelToArray(s, x, y, colMieng, col15Phut, colMotTiet, arrMark, arrTime, timeNow, timeToEdit, position, isNx,
diffMessage):
lengthCol = [colMieng, col15Phut, colMotTiet]
for t in range(3):
for i in range(lengthCol[t]):
value = unicode(s.cell(x, y + i).value)
value = value.replace(' ', '')
value = value.replace(',', '.')
if isNx:
value = convertCharToDigit(value)
if (isDifference(value, arrMark[t * MAX_COL + i + 1])) & (arrTime[t * MAX_COL + i + 1] != ''):
diffMessage[0] += cellname(x, y + i) + ' '
if ((arrTime[t * MAX_COL + i + 1] != '') & (position != 4)):
if (timeNow - int(arrTime[t * MAX_COL + i + 1])) > timeToEdit:
if isDifference(value, arrMark[t * MAX_COL + i + 1]):
return u" Ô " + cellname(x, y + i) + u' không được sửa điểm.'
if (value == ""):
arrTime[t * MAX_COL + i + 1] = ""
elif isDifference(value, arrMark[t * MAX_COL + i + 1]):
arrTime[t * MAX_COL + i + 1] = str(timeNow)
arrMark[t * MAX_COL + i + 1] = value
y += lengthCol[t]
return ""
开发者ID:tranvictor,项目名称:truongnha,代码行数:25,代码来源:importMark.py
示例5: validate
def validate(s,isNx):
x=11
y=4
if isNx==False:
for i in range(x,s.nrows):
for j in range(4,20):
try:
value = str(s.cell(i,j).value)
value = value.replace(' ','')
if len(value) !=0:
value1 = float(value)
if (value1<0) | (value1>10):
return u'Điểm ở ô '+cellname(i,j)+u' không nằm trong [0,10] '
except Exception as e:
return u'Điểm ở ô '+cellname(i,j)+u' không hợp lệ'
return ''
else:
for i in range(x,s.nrows):
for j in range(4,23):
try:
value = str(s.cell(i,j).value)
value = value.replace(' ','').lower()
if len(value)!=0:
if (value!='g') & (value!='k') & (value!='tb') & (value!='y') & (value!='kem') & (value!='kém') :
return u'Lỗi ở ô '+cellname(i,j)+u'. Chỉ dùng các kí tự sau để cho điểm G,K,TB,Y,Kem.'
except Exception as e:
return u'Lỗi ở ô '+cellname(i,j)+ u'. Chỉ dùng các kí tự sau để cho điểm G,K,TB,Y,Kem.'
return ''
开发者ID:tungvx,项目名称:qlnt,代码行数:30,代码来源:importMark.py
示例6: print_labels
def print_labels(sh, labs, title):
if not labs:return
for rlo, rhi, clo, chi in labs:
print("%s label range %s:%s contains:"
% (title, xlrd.cellname(rlo, clo), xlrd.cellname(rhi-1, chi-1)))
for rx in xrange(rlo, rhi):
for cx in xrange(clo, chi):
print(" %s: %r" % (xlrd.cellname(rx, cx), sh.cell_value(rx, cx)))
开发者ID:ClayMason,项目名称:BlackrockFBP,代码行数:8,代码来源:runxlrd.py
示例7: introspect_surveysheet
def introspect_surveysheet(sheet):
print sheet.name
print sheet.nrows
print sheet.ncols
for row_index in range(sheet.nrows):
for col_index in range(sheet.ncols):
print xlrd.cellname(row_index, col_index), '-', #nur den index-namen einer zelle e.g. A1 B4 etc.
print sheet.cell(row_index, col_index).value #wert einer zelle e.g. 'steuer'
return
开发者ID:fkuhn,项目名称:multiprs,代码行数:9,代码来源:multiMetaReader.py
示例8: map_batsmen_stats
def map_batsmen_stats():
player_stats = {}
player_matchid = {}
for row_index in range(2,sheet.nrows):
for col_index in range(1,sheet.ncols):
if cellname(row_index,col_index)[0] == 'E':
curr_batsmen = sheet.cell(row_index,col_index).value
if curr_batsmen not in player_matchid:
player_matchid[curr_batsmen] = []
if curr_batsmen in player_stats:
player_stats[curr_batsmen][0]+=sheet.cell(row_index,col_index+3).value
else:
player_stats[curr_batsmen] = [sheet.cell(row_index,col_index+3).value,0,0]
curr_match_id = sheet.cell(row_index,col_index-2).value
if curr_match_id not in player_matchid[curr_batsmen]:
player_stats[curr_batsmen][2]+=1
player_matchid[curr_batsmen].append(curr_match_id)
if cellname(row_index,col_index)[0] == 'N':
dismissed_batsmen = sheet.cell(row_index,col_index).value
if dismissed_batsmen in player_stats:
player_stats[dismissed_batsmen][1]+=1
else:
player_stats[dismissed_batsmen] = [0,1,1]
curr_match_id = sheet.cell(row_index,col_index-11).value
if dismissed_batsmen in player_matchid:
player_matchid[dismissed_batsmen].append(curr_match_id)
else:
player_matchid[dismissed_batsmen]=[]
player_matchid[dismissed_batsmen].append(curr_match_id)
#Create new sheet
workbook,batsmen_stat_sheet = create_new_sheet("batsmen_stats.xls")
#Initialize rows,columns
row_count = 0
batsmen_stat_sheet.write(0,0,"Player Name")
batsmen_stat_sheet.write(0,1,"Number of Innings")
batsmen_stat_sheet.write(0,2,"Total Runs")
batsmen_stat_sheet.write(0,3,"Not Outs")
batsmen_stat_sheet.write(0,4,"Batting Average")
row_count+=1
for x in player_stats:
batsmen_stat_sheet.write(row_count,0,x)
batsmen_stat_sheet.write(row_count,1,player_stats[x][2])
batsmen_stat_sheet.write(row_count,2,player_stats[x][0])
batsmen_stat_sheet.write(row_count,3,player_stats[x][2]-player_stats[x][1])
if (player_stats[x][1]):
batsmen_stat_sheet.write(row_count,4,
"%.2f"%float((player_stats[x][0])/(player_stats[x][1])))
else:
batsmen_stat_sheet.write(row_count,4,0)
row_count+=1
workbook.close()
开发者ID:PythonExplorer,项目名称:LatentView_TNT,代码行数:56,代码来源:data_preparation.py
示例9: complete_batsmen_performance
def complete_batsmen_performance():
sheet1 = open("grey_relation_grades2011.xls")
sheet2 = open("grey_relation_grades2012.xls")
sheet3 = open("grey_relation_grades2013.xls")
sheet4 = open("grey_relation_grades2014.xls")
total_batsmen_grd = {}
for row_index in range(1,sheet1.nrows):
for col_index in range(sheet1.ncols):
if cellname(row_index,col_index)[0] == 'A':
curr_batsmen = sheet1.cell(row_index,col_index).value
curr_grade = sheet1.cell(row_index,col_index+1).value
if curr_batsmen not in total_batsmen_grd:
total_batsmen_grd[curr_batsmen] = 5*curr_grade
for row_index in range(1,sheet2.nrows):
for col_index in range(sheet2.ncols):
if cellname(row_index,col_index)[0] == 'A':
curr_batsmen = sheet2.cell(row_index,col_index).value
curr_grade = sheet2.cell(row_index,col_index+1).value
if curr_batsmen not in total_batsmen_grd:
total_batsmen_grd[curr_batsmen] = curr_grade
else:
total_batsmen_grd[curr_batsmen] += 35*curr_grade
for row_index in range(1,sheet3.nrows):
for col_index in range(sheet3.ncols):
if cellname(row_index,col_index)[0] == 'A':
curr_batsmen = sheet3.cell(row_index,col_index).value
curr_grade = sheet3.cell(row_index,col_index+1).value
if curr_batsmen not in total_batsmen_grd:
total_batsmen_grd[curr_batsmen] = curr_grade
else:
total_batsmen_grd[curr_batsmen] += 45*curr_grade
for row_index in range(1,sheet4.nrows):
for col_index in range(sheet4.ncols):
if cellname(row_index,col_index)[0] == 'A':
curr_batsmen = sheet4.cell(row_index,col_index).value
curr_grade = sheet4.cell(row_index,col_index+1).value
if curr_batsmen not in total_batsmen_grd:
total_batsmen_grd[curr_batsmen] = curr_grade
else:
total_batsmen_grd[curr_batsmen] += 15*curr_grade
#Create new sheet
workbook,grey_relation_grades_sheet = create_new_sheet(
"final_grey_relation_grades.xls"
)
#Initialize rows,columns
row_count = 0
grey_relation_grades_sheet.write(0,0,"Player Name")
grey_relation_grades_sheet.write(0,1,"Grade")
row_count+=1
for x in total_batsmen_grd:
grey_relation_grades_sheet.write(row_count,0,x)
grey_relation_grades_sheet.write(row_count,1,total_batsmen_grd[x]/100.0)
row_count+=1
workbook.close()
开发者ID:PythonExplorer,项目名称:LatentView_TNT,代码行数:56,代码来源:grey_relation_analysis.py
示例10: read_xls
def read_xls(file_path,sheet_name):
"""读取xls中的数据
:param file_path 文件路径
:param sheet_name sheet名
:return header,rows
"""
workbook = xlrd.open_workbook('成绩单.xls')
for booksheet in workbook.sheets():
print booksheet.name
for row in xrange(booksheet.nrows):
for col in xrange(booksheet.ncols):
print xlrd.cellname(row, col)
print booksheet.cell(row, col).value
开发者ID:hulingfeng211,项目名称:mywork,代码行数:14,代码来源:utils.py
示例11: grades_dictionary
def grades_dictionary(book_name):
book=open_workbook(book_name)
sheet=book.sheet_by_index(0)
gradebook={}
# Temporary lists to store our course codes,names and grades after iteration
templist1=[]
templist2=[]
templist3=[]
i=1
for row_index in range(sheet.nrows):
for col_index in range(sheet.ncols):
# 'A' represent course code
if 'A' in cellname(row_index,col_index):
# We don't care about the first row so we skip it
if i==1:
i=i+1
continue
a=sheet.cell(row_index,col_index).value
a=a.encode('ascii') # This is to get rid of the unicode character
templist1.append(a)
if 'B' in cellname(row_index,col_index):
if i==2:
i=i+1
continue
b=sheet.cell(row_index,col_index).value
b=b.encode('ascii')
templist2.append(b)
if 'C' in cellname(row_index,col_index):
if i==3:
i=i+1
continue
c=sheet.cell(row_index,col_index).value
c=c.encode('ascii')
templist3.append(c)
subject_list=[]
# We now combine the course code and course name into one name
for index, item in enumerate(templist2):
subject_list.append(templist1[index]+' '+templist2[index])
# We call a different function to convert letter grades to their numeric value
grades_to_digits=convert_letter_to_dig(templist3)
# We append the subject and numeric grade to the gradebook then return it
for index,item in enumerate(subject_list):
gradebook[item]=grades_to_digits[index]
return gradebook
开发者ID:DrJayLight,项目名称:Course_Recommendation_System,代码行数:48,代码来源:jareth_moyo.py
示例12: check_total_runs
def check_total_runs():
total_runs=0
for row_index in range(2,sheet.nrows):
for col_index in range(1,sheet.ncols):
if cellname(row_index,col_index)[0] == 'H':
total_runs+=sheet.cell(row_index,col_index).value
return total_runs
开发者ID:PythonExplorer,项目名称:LatentView_TNT,代码行数:7,代码来源:data_preparation.py
示例13: most_catches_stumps
def most_catches_stumps(sheet_name):
catches = {}
stumps = {}
sheet = open(sheet_name)
run_outs = 0
rvic = {}
for row_index in range(1,sheet.nrows):
for col_index in range(0,sheet.ncols):
if cellname(row_index,col_index)[0] == 'Y':
wicket_kind = sheet.cell(row_index,col_index).value
fielder = sheet.cell(row_index,col_index+1).value
victim = sheet.cell(row_index,col_index+2).value
if wicket_kind == "run out":
run_outs+=1
if victim not in rvic:
rvic[victim] = 0
rvic[victim]+=1
if wicket_kind == "caught":
if fielder not in catches:
catches[fielder] = 0
catches[fielder]+=1
if wicket_kind == "stumps":
if fielder not in stumps:
stumps[fielder] = 0
stumps[fielder]+=1
print(run_outs)
s_rvic = sorted(rvic.items(), key=operator.itemgetter(1))
s_catches = sorted(catches.items(), key=operator.itemgetter(1))
s_stumps = sorted(stumps.items(), key=operator.itemgetter(1))
print(s_rvic)
print(s_catches)
print(s_stumps)
开发者ID:PythonExplorer,项目名称:LatentView_TNT,代码行数:32,代码来源:matchwise_stats.py
示例14: ducks_stats
def ducks_stats(sheet_name):
sheet = open(sheet_name)
batsmen_duck_count = {}
for row_index in range(1,sheet.nrows):
for col_index in range(0,sheet.ncols):
if cellname(row_index,col_index)[0] == 'A':
curr_player = sheet.cell(row_index,col_index+1).value
player_runs = sheet.cell(row_index,col_index+2).value
is_notout = sheet.cell(row_index,col_index+4).value
if player_runs == 0 and is_notout == "NO":
if curr_player not in batsmen_duck_count:
batsmen_duck_count[curr_player]=0
batsmen_duck_count[curr_player]+=1
#Create new sheet
workbook,ducks_stats_sheet = create_new_sheet("ducks_stats.xls")
#Initialize rows,columns
row_count = 0
ducks_stats_sheet.write(0,0,"Player Name")
ducks_stats_sheet.write(0,1,"Ducks Count")
row_count+=1
for x in batsmen_duck_count:
ducks_stats_sheet.write(row_count,0,x)
ducks_stats_sheet.write(row_count,1,batsmen_duck_count[x])
row_count+=1
workbook.close()
开发者ID:PythonExplorer,项目名称:LatentView_TNT,代码行数:25,代码来源:matchwise_stats.py
示例15: parse
def parse(infile, outfile):
"""
Converts an Excel file into text
Returns a formatted text file for comparison using git diff.
"""
book = xl.open_workbook(infile)
num_sheets = book.nsheets
print book.sheet_names()
# print "File last edited by " + book.user_name + "\n"
outfile.write("File last edited by " + book.user_name + "\n")
def get_cells(sheet, rowx, colx):
return sheet.cell_value(rowx, colx)
# loop over worksheets
for index in range(0, num_sheets):
# find non empty cells
sheet = book.sheet_by_index(index)
outfile.write("=================================\n")
outfile.write("Sheet: " + sheet.name + "[ " + str(sheet.nrows) + " , " + str(sheet.ncols) + " ]\n")
outfile.write("=================================\n")
for row in range(0, sheet.nrows):
for col in range(0, sheet.ncols):
content = get_cells(sheet, row, col)
if content <> "":
outfile.write(" " + unicode(xl.cellname(row, col)) + ": " + unicode(content) + "\n")
print "\n"
开发者ID:emorisse,项目名称:spreadsheetdiff,代码行数:32,代码来源:git_diff_xls.py
示例16: parseSheet
def parseSheet(infile,outfile):
"""
Taken From: https://github.com/willu47/git_diff_xlsx/blob/master/git_diff_xlsx.py
Converts an Excel file into text
Returns a formatted text file for comparison using git diff.
"""
book = xl.open_workbook(infile)
num_sheets = book.nsheets
print( book.sheet_names())
# print "File last edited by " + book.user_name + "\n"
outfile.write("File last edited by " + book.user_name + "\n")
def get_cells(sheet, rowx, colx):
return sheet.cell_value(rowx, colx)
# loop over worksheets
for index in range(0,num_sheets):
# find non empty cells
sheet = book.sheet_by_index(index)
outfile.write("=================================\n")
outfile.write("Sheet: " + sheet.name + "[ " + str(sheet.nrows) + " , " + str(sheet.ncols) + " ]\n")
outfile.write("=================================\n")
for row in range(0,sheet.nrows):
for col in range(0,sheet.ncols):
content = get_cells(sheet, row, col)
if content != "":
outfile.write(" " + str(xl.cellname(row,col)) + ": " + str(content) + "\n")
print( "\n")
开发者ID:EWhite613,项目名称:xlsm-git-diff-test,代码行数:34,代码来源:git_diff_xlsm.py
示例17: get_sheet_values
def get_sheet_values(self, sheetname, includeEmptyCells=True):
"""
Returns the values from the sheet name specified.
Arguments:
| Sheet Name (string) | The selected sheet that the cell values will be returned from. |
| Include Empty Cells (default=True) | The empty cells will be included by default. To deactivate and only return cells with values, pass 'False' in the variable. |
Example:
| *Keywords* | *Parameters* |
| Open Excel | C:\\Python27\\ExcelRobotTest\\ExcelRobotTest.xls |
| Get Sheet Values | TestSheet1 |
"""
my_sheet_index = self.sheetNames.index(sheetname)
sheet = self.wb.sheet_by_index(my_sheet_index)
data = {}
for row_index in range(sheet.nrows):
for col_index in range(sheet.ncols):
cell = cellname(row_index, col_index)
value = sheet.cell(row_index, col_index).value
data[cell] = value
if includeEmptyCells is True:
sortedData = natsort.natsorted(data.items(), key=itemgetter(0))
return sortedData
else:
data = dict([(k, v) for (k, v) in data.items() if v])
OrderedData = natsort.natsorted(data.items(), key=itemgetter(0))
return OrderedData
开发者ID:qitaos,项目名称:robotframework-excellibrary,代码行数:29,代码来源:ExcelLibrary.py
示例18: convert_xl_row
def convert_xl_row(xlrdbook, xlrdsheetname, rownum):
'''Converts an xlrd excel worksheet row into a standard python format.
Empty or blank cells -> None
Number or text -> float or string
Boolean -> True or False
Date -> date string as rendered by datetime.datetime
Raises ValueError if a cell has an error.'''
xlrdsheet = xlrdbook.sheet_by_name(xlrdsheetname)
ret = []
for i, cell in enumerate(xlrdsheet.row(rownum)):
if (cell.ctype == _xlrd.XL_CELL_EMPTY or
cell.ctype == _xlrd.XL_CELL_BLANK):
ret.append(None)
elif (cell.ctype == _xlrd.XL_CELL_NUMBER or
cell.ctype == _xlrd.XL_CELL_TEXT):
ret.append(cell.value)
elif cell.ctype == _xlrd.XL_CELL_BOOLEAN:
ret.append(bool(cell.value))
elif cell.ctype == _xlrd.XL_CELL_DATE:
dt = _xlrd.xldate_as_tuple(cell.value, xlrdbook.datemode)
d = str(_datetime.datetime(*dt))
ret.append(d)
elif cell.ctype == _xlrd.XL_CELL_ERROR:
raise ValueError(
' '.join(['Cell', _xlrd.cellname(rownum, i), 'in sheet',
xlrdsheet.name, 'has an error']))
else:
raise ValueError('Unknown cell type') # error in xlrd
return ret
开发者ID:kbase,项目名称:kb_sdk,代码行数:29,代码来源:filetools.py
示例19: parse
def parse(file,outfile):
book = xl.open_workbook(file)
num_sheets = book.nsheets
print book.sheet_names()
# print "File last edited by " + book.user_name + "\n"
outfile.write("File last edited by " + book.user_name + "\n")
def get_cells(sheet, rowx, colx):
return sheet.cell_value(rowx, colx)
# loop over worksheets
for index in range(0,num_sheets):
# find non empty cells
sheet = book.sheet_by_index(index)
outfile.write("=================================\n")
outfile.write("Sheet: " + sheet.name + "[ " + str(sheet.nrows) + " , " + str(sheet.ncols) + " ]\n")
outfile.write("=================================\n")
for row in range(0,sheet.nrows):
for col in range(0,sheet.ncols):
content = get_cells(sheet, row, col)
if content <> "":
outfile.write(" " + str(xl.cellname(row,col)) + ": " + str(content) + "\n")
print "\n"
开发者ID:adamtelfer,项目名称:exceldiff,代码行数:28,代码来源:git_diff_xlsx.py
示例20: map_match_bowler_stats
def map_match_bowler_stats():
match_bowler_stats = {}
for row_index in range(2,sheet.nrows):
for col_index in range(1,sheet.ncols):
if cellname(row_index,col_index)[0] == 'C':
curr_match_id = sheet.cell(row_index,col_index).value
curr_bowler = sheet.cell(row_index,col_index+14).value
curr_wides = sheet.cell(row_index,col_index+17).value
curr_nb = sheet.cell(row_index,col_index+18).value
curr_byes = sheet.cell(row_index,col_index+19).value
curr_lbyes = sheet.cell(row_index,col_index+20).value
total_runs = sheet.cell(row_index,col_index+21).value
curr_runs = total_runs - curr_byes - curr_lbyes;
if curr_match_id in match_bowler_stats:
if curr_bowler in match_bowler_stats[curr_match_id]:
if curr_wides == 0 and curr_nb == 0:
match_bowler_stats[curr_match_id][curr_bowler][0]+=1
match_bowler_stats[curr_match_id][curr_bowler][1]+=curr_runs
is_wicket = sheet.cell(row_index,col_index+22).value
if is_wicket in ["caught","caught and bowled","stumped","bowled","lbw"]:
match_bowler_stats[curr_match_id][curr_bowler][2]+=1
else:
match_bowler_stats[curr_match_id][curr_bowler]= [0,0,0]
if curr_wides == 0 and curr_nb == 0:
match_bowler_stats[curr_match_id][curr_bowler][0]+=1
match_bowler_stats[curr_match_id][curr_bowler][1]+=curr_runs
is_wicket = sheet.cell(row_index,col_index+22).value
if is_wicket in ["caught","caught and bowled","stumped","bowled","lbw"]:
match_bowler_stats[curr_match_id][curr_bowler][2]+=1
else:
match_bowler_stats[curr_match_id] = {}
match_bowler_stats[curr_match_id][curr_bowler]= [0,0,0]
if curr_wides == 0 and curr_nb == 0:
match_bowler_stats[curr_match_id][curr_bowler][0]+=1
match_bowler_stats[curr_match_id][curr_bowler][1]+=curr_runs
is_wicket = sheet.cell(row_index,col_index+22).value
if is_wicket in ["caught","caught and bowled","stumped","bowled","lbw"]:
match_bowler_stats[curr_match_id][curr_bowler][2]+=1
#Create new sheet
workbook,match_bowler_stats_sheet = create_new_sheet("match_bowler_stats.xls")
#Initialize rows,columns
row_count = 0
match_bowler_stats_sheet.write(0,0,"Match ID")
match_bowler_stats_sheet.write(0,1,"Bowler")
match_bowler_stats_sheet.write(0,2,"Balls")
match_bowler_stats_sheet.write(0,3,"Runs")
match_bowler_stats_sheet.write(0,4,"Wickets")
row_count+=1
#Write into workbook
for x in match_bowler_stats:
for y in match_bowler_stats[x]:
match_bowler_stats_sheet.write(row_count,0,x)
match_bowler_stats_sheet.write(row_count,1,y)
match_bowler_stats_sheet.write(row_count,2,match_bowler_stats[x][y][0])
match_bowler_stats_sheet.write(row_count,3,match_bowler_stats[x][y][1])
match_bowler_stats_sheet.write(row_count,4,match_bowler_stats[x][y][2])
row_count+=1
workbook.close()
开发者ID:PythonExplorer,项目名称:LatentView_TNT,代码行数:59,代码来源:data_preparation.py
注:本文中的xlrd.cellname函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论