[英]excel: 0 in [h]:mm format becomes -1 when I save it to another file
*Let's say I have an excel file. *假设我有一个Excel文件。 A1 value is 0. Its format is [h]:mm. A1值为0。其格式为[h]:mm。 And I want to copy that value and save it to another excel file. 我想复制该值并将其保存到另一个Excel文件中。 But that value becomes -1. 但是该值变为-1。 Why is it happening? 为什么会这样呢? Can anyone help me? 谁能帮我?
A1 value is 0.(see above) A1值为0。
I copied the value of A1 and pasted it to another excel file and saved it. 我复制了A1的值并将其粘贴到另一个Excel文件中并保存。 Now it changed to -1. 现在它变为-1。
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. 我能说得最好的是由于openpyxl当前在保存到文件时处理时期的方式。 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. 即使您只显示日期时间的时间部分,Excel似乎实际上将您的0:00
存储为日期时间。
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
例如,将时间设置为2018-01-01 0:00
,然后将其格式化为h:mm
Not sure if this approach will meet all your requirements but it did copy over without the -1
for me 不知道这种方法是否可以满足您的所有要求,但是对于我来说,它确实没有使用-1
进行了复制
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.