【问题标题】:Read Excel file in python with the same format as the Excel file在python中读取与Excel文件格式相同的Excel文件
【发布时间】:2021-10-15 07:21:53
【问题描述】:

我想用 Python 读取一个 Excel 文件,其数据格式与 Excel 文件完全相同。

我有一个 Excel 文件,其中一些列采用 int 格式,即 2,000。其他浮点格式,即 1,999.52。另一列日期为“长格式”,即 2020 年 12 月 31 日,写为 2020 年 12 月 31 日,星期四。

鉴于这个 Excel 文件中有一些公式,我的代码是:

excel = load_workbook('excelfileroute', data_only=True)

有没有办法将 Excel 文件中的所有数据作为字符串导入,而数据格式保持不变?或者我可以导入保持 Excel 文件格式的数据的方法?

谢谢

【问题讨论】:

  • 这只有在您为 Excel 的数字格式编写自己的解释器时才有可能。

标签: python python-3.x excel pandas openpyxl


【解决方案1】:

可能最简单的方法是正常读取数据,然后在最后将其保存回原始数据类型。

【讨论】:

    猜你喜欢
    • 2018-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多