I used pandas read_excel, and for these cells got only the numeric values and not the "EUR" (currency).
Then I tried using openpyxl to read the cell values and type I got "int" and not "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.
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 cells can be configured to show a "currency" on theire own. 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.
You can query each cell for its the format and parse the EUR
from it:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.