用python设置excel中单元格字体颜色的方法

#设置excel中单元格字体颜色为绿色
def setFont(self,row,col,filename,index):
book=xlrd.open_workbook(self.data_dir(“data”,filename),formatting_info=True)
cbook=copy.copy(book)
csheet=cbook.get_sheet(0)
style=xlwt.XFStyle()
font=xlwt.Font()
font.colour_index=index
style.font=font
csheet.write(row,col,self.getCellValue(row,col,filename),style)
cbook.save(self.data_dir(“data”,filename))
#设置整张表格字体颜色为黑色
def setBlack(self,filename):
rows=self.getRowNum(filename)
cols=self.getColNum(filename)
for i in range(rows):
for j in range(cols):
self.setFont(i,j,filename,0)

你可能感兴趣的:(接口自动化测试)