简体   繁体   中英

excel: 0 in [h]:mm format becomes -1 when I save it to another file

*Let's say I have an excel file. A1 value is 0. Its format is [h]:mm. And I want to copy that value and save it to another excel file. But that value becomes -1. Why is it happening? Can anyone help me?

在此处输入图片说明

A1 value is 0.(see above)

在此处输入图片说明

I copied the value of A1 and pasted it to another excel file and saved it. Now it changed to -1.

Here is my code. 在此处输入图片说明

I want to copy and paste without changing any value. Can anyone help me?

The best I can tell this is due to the way that openpyxl currently handles the epoch time when saving to the file. It looks like Excel is actually storing your 0:00 as a datetime even though you are only showing the time part of the datetime.

One work around to this would be to add a date component to the time (so it doesn't default to the epoch). For example set the time to 2018-01-01 0:00 and then format it to h:mm

Not sure if this approach will meet all your requirements but it did copy over without the -1 for me

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM