是否可以使用xlwt强制单元格始终显示4位小数?而不考虑小数点后实际出现的数字。我已经做了一些搜索,我可以找到一个字符串,总是减少到小数点后两位,但我需要在我的工作表上的某些单元格显示4。
发布于 2013-04-26 15:06:55
使用xlwt样式。下面是一个简单的例子:
import xlwt
book = xlwt.Workbook()
sheet = book.add_sheet("test")
decimal_style = xlwt.XFStyle()
decimal_style.num_format_str = '0.0000'
sheet.write(0, 0, 1.23456789, decimal_style)
sheet.write(0, 1, 1.01, decimal_style)
book.save('test.xls')或者您可以使用xlwt.easyxf来定义样式。希望这能有所帮助。
https://stackoverflow.com/questions/16176211
复制相似问题