def format_number_with_openpyxl(f, cell, wb): s_fmt = cell.number_format a_fmt = numfmt.extract_number_format(s_fmt) if a_fmt: return numfmt.format_number(f, a_fmt, ',', '.') else: return "%g" % f
def format_number_with_xlrd(f, cell, wb): xf = wb.xf_list[cell.xf_index] fmt_key = xf.format_key fmt = wb.format_map[fmt_key] s_fmt = fmt.format_str a_fmt = numfmt.extract_number_format(s_fmt) if a_fmt: s_f = numfmt.format_number(f, a_fmt, ',', '.') else: s_f = "%g" % f return s_f
def format_number(f, cell, wb): xf = wb.xf_list[cell.xf_index] fmt_key = xf.format_key fmt = wb.format_map[fmt_key] s_fmt = fmt.format_str a_fmt = numfmt.extract_number_format(s_fmt) if a_fmt: s_f = numfmt.format_number(f, a_fmt, div1000, div1) else: s_f = str(f) return s_f
def one_test(f, s_fmt, s_expected): a = numfmt.extract_number_format(s_fmt) s_f = numfmt.format_number(f, a, div1000=',', div1='.') self.assertEqual(s_f, s_expected)