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)
成功
![](https://img2022.cnblogs.com/blog/1546737/202206/1546737-20220621133933839-437708470.png)