Numeric looking value in Text formatted cell has incorrect data_type

Issue #589 invalid
Noah Carnahan
created an issue

I have an xlsx file with the string "1234" in a cell. The formatting of the cell is "Text". However, when I load the file with openpyxl the data_type of the cell is "n". I was expecting the value to be interpreted as a string, but the relationship between data_type and cell formatting may be more complex than I realize. Thanks for the great library btw!

Attached is the sheet in question.

>>> from openpyxl import load_workbook
>>> wb = load_workbook(filename="bug.xlsx", guess_types=False)
>>> wb['Sheet1']['A1'].data_type

Comments (3)

  1. CharlieC

    openpyxl pays no attention to the formatting of a cell – why should it? this is for presentation only – except for dates and times, because Excel has no other way of distinguishing between them and numbers. If you want to store numbers as text then you must prefix them with ".

  2. Log in to comment