xlrd模块去读excel时会将数字类型的自动转化为浮点数,这是一个小坑。在网上查了一下,该模块的作者也说过Excel treats all numbers as floats. In general, it doesn't care whether your_number % 1 == 0.0 is true or not
我们可以简单的判断读取的是不是数字,然后将其转化为int

# ctype为2时表示为number
cell = table.cell(0, 0)
if cell.ctype == 2 and cell.value % 1 == 0:
    cell_value = int(cell.value)

相关文章:

  • 2021-08-20
  • 2021-11-25
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-06
  • 2021-11-16
  • 2022-01-28
  • 2021-11-15
  • 2022-01-02
  • 2021-07-16
  • 2022-01-24
相关资源
相似解决方案