EXCEL 写入数据保持原样式
importxlwtimportxlrdimportxlutilsimportxlutils.copyclassExcelHandle():def __init__(self, filename):
self.filename=filename
self.test_data= xlrd.open_workbook(self.filename,formatting_info=True) #保留原格式
self.sheet =self.test_data.sheet_by_index(0)defwriteExcel(self,row,col,value):
self.row=row
self.col=col
self.args=value
style=xlwt.XFStyle()
oldsheet= xlrd.open_workbook(self.filename,formatting_info=True)
newsheet=xlutils.copy.copy(oldsheet)
newwrite=newsheet.get_sheet(0)
newwrite.write(self.row, self.col, str(value), style)
newsheet.save(self.filename)defreadExcel(self, row,col):
comlist=str(self.sheet.cell_value(row, col))returncomlistif __name__ == '__main__':
t= ExcelHandle('bookname.xlsx')for i in range(2,15):for j in ra