openpyxl reads cell with format

Thomas Jollans tjol at tjol.eu
Mon Jun 5 16:39:12 EDT 2017


On 05/06/17 16:46, Mahmood Naderan wrote:
>> if the cell is an Excel date, it IS stored as a numeric
> 
> As I said, the "shape" of the cell is similar to date. The content which is "4-Feb" is not a date. It is a string which I expect from cell.value to read it as "4-Feb" and nothing else.
> 
> Also, I said before that the file is downloaded from a website. That means, from a button on a web page, I chose "export as excel" to download the data. I am pretty sure that auto format feature of the excel is trying to convert it as a date.
> 
> 
> So, I am looking for a way to ignore such auto formatting.

Actually, you're looking for a way to find out how Excel formats the
date cell (this is presumably stored in the xlsx file) and to format the
value in the same way.

The content of the cell is a (numeric) date value. The cell has an
associated date format. You can verify this if you open the file in
Excel. If you don't believe what Excel tells you, you can have a look at
the actual XML.

(I have no idea how to get the date format with openpyxl, but I'm sure
that's what you want to do if you need the string "4-Feb" - unless you
can show us that that string is stored in the XML file)



-- Thomas




More information about the Python-list mailing list