![](/img/trans.png)
[英]How to insert and format values cell by cell in an XLSX file using openpyxl
[英]Unable to detect EUR in a cell of any .xlsx file, using pandas or openpyxl
我使用了熊猫read_excel,对于这些单元格,只得到了数值,而没有得到“ EUR”(货币)。
然后,我尝试使用openpyxl读取单元格值并输入“ int”而不是“ str”。
使用Libre calc或MS excel之类的excel编辑器,我们可以将货币转换为所需的输出,但是,我需要找到一种方法来检测EUR
为货币并将相应的值存储在数据库中。
我在哪里错了? 我还有其他方法可以检测到它吗?
我已经在此处附加了excel工作表。Google工作表链接。
可以将Excel单元格配置为单独显示“货币”。 这只是视觉上的,内部是商店编号以及属于该单元格的格式元信息。 您不能从单元格值中提取EUR,而是从格式字符串中提取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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.