openpyxl reads cell with format

Mahmood Naderan nt_mahmood at yahoo.com
Mon Jun 5 15:33:12 EDT 2017


OK thank you very much. As you said, it seems that it is too late for my python script.

 
Regards,
Mahmood


On Monday, June 5, 2017 10:41 PM, Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:



On Mon, 5 Jun 2017 14:46:18 +0000 (UTC), Mahmood Naderan via Python-list

<python-list at python.org> declaimed the following:


>>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.

>


    Then you'll have to modify the Excel file before the "export" to tell

IT that the column is plain text BEFORE the data goes into the column.


    The normal behavior for Excel is: if something looks like a date

(partial or full) when entered, Excel will store it as a numeric "days from

epoch" and flag the cell as a "date" field. The visual representation is up

to the client -- as my sample table shows, the very same input value looks

different based upon how the column is defined.


>

>So, I am looking for a way to ignore such auto formatting.

>


    By the time Python sees it, it is too late -- all you have is an

integer number tagged as a "date", and an import process that renders that

number as a Python datetime object (which you can then render however you

want

https://docs.python.org/2/library/datetime.html#strftime-and-strptime-behavior

)

-- 

    Wulfraed                 Dennis Lee Bieber         AF6VN

    wlfraed at ix.netcom.com    HTTP://wlfraed.home.netcom.com/


-- 

https://mail.python.org/mailman/listinfo/python-list



More information about the Python-list mailing list