简体   繁体   English

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

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

在此处输入图片说明

I used pandas read_excel, and for these cells got only the numeric values and not the "EUR" (currency). 我使用了熊猫read_excel,对于这些单元格,只得到了数值,而没有得到“ EUR”(货币)。

Then I tried using openpyxl to read the cell values and type I got "int" and not "str". 然后,我尝试使用openpyxl读取单元格值并输入“ int”而不是“ str”。

Using excel editors like Libre calc or MS excel we can convert the currency to the desired output, although, I need to find a way to detect EUR as a currency and store the corresponding value in my DB. 使用Libre calc或MS excel之类的excel编辑器,我们可以将货币转换为所需的输出,但是,我需要找到一种方法来检测EUR为货币并将相应的值存储在数据库中。

Where I am I going wrong? 我在哪里错了? Is there any other way I can detect it? 我还有其他方法可以检测到它吗?

I have attached the excel sheet here.. Google sheets link.. 我已经在此处附加了excel工作表。Google工作表链接。

Excel cells can be configured to show a "currency" on theire own. 可以将Excel单元格配置为单独显示“货币”。 This is just a visual, internally in stores numbers and a format meta-info that belongs to the cell. 这只是视觉上的,内部是商店编号以及属于该单元格的格式元信息。 You cannot extract EUR from the cells value, but from the format string. 您不能从单元格值中提取EUR,而是从格式字符串中提取EUR。

You can query each cell for its the format and parse the EUR from it: 您可以查询每个单元格的格式并从中解析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

Output: 输出:

(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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM