python设置excel文本格式为数字不生效解决

问题描述:
  设置excel单元格百分比格式为数字老是不生效

sheet.cell(row=1, column=5).number_format = '0.00%'

修改代码给该单元格赋值的语句

原代码:

sheet.cell(row=1, column=5).value = '{:.2%}'.format(float(item['this_week_p2_bug']) / float(item['this_week_total_bug']))

修改后代码:

sheet.cell(row=1, column=5).value = round(float(item['this_week_p1_bug']) / float(item['this_week_total_bug']), 2)

成功

 

posted on 2022-06-21 13:40  阿虾  阅读(368)  评论(0编辑  收藏  举报

导航