使用 pandas 或 openpyxl 无法在任何 .xlsx 文件的单元格中检测到 EUR

Unable to detect EUR in a cell of any .xlsx file, using pandas or openpyxl

我使用了 pandas read_excel,对于这些单元格,只有数值而不是 "EUR"(货币)。

然后我尝试使用 openpyxl 读取单元格值并输入我得到的 "int" 而不是 "str"。

使用 Libre calc 或 MS excel 等 excel 编辑器,我们可以将货币转换为所需的输出,不过,我需要找到一种方法来检测 EUR 作为货币并将相应的值存储在我的数据库中。

我哪里错了?有没有其他方法可以检测到它?

我在这里附上了 excel sheet..Google sheets link..

Excel 单元格可以配置为单独显示 "currency"。这只是一个可视化的内部存储数字和属于单元格的格式元信息。您不能从单元格值中提取 EUR,而是从格式字符串中提取。

您可以查询每个单元格的格式并从中解析 EUR

from openpyxl import Workbook, load_workbook

wb = load_workbook(r"stack_excel.xlsx")
ws = wb.worksheets[0]

for n in range(1,10):
    _cell = ws.cell(1,n)              # get a cell
    print((1,n), _cell.number_format) # read the number format of this cell

输出:

(1, 1) General
(1, 2) General
(1, 3) General
(1, 4) General
(1, 5) General
(1, 6) General
(1, 7) 0
(1, 8) [$EUR]\ 0
(1, 9) [$EUR]\ 0