简体   繁体   English

excel:当我将其保存到另一个文件时,[h]:mm格式的0变为-1

[英]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。

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. 我能说得最好的是由于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.

相关问题 当我尝试在 python 中将 pandas 保存为 excel 文件时出错 - Error when I try to save pandas as excel file in python Excel [h]:mm 持续时间到 pandas timedelta - Excel [h]:mm duration to pandas timedelta 当我将元组列表追加到另一个列表时,它变为空 - When I append list of tuples to another list it becomes empty 当我将它保存为 Excel 文件时,如何使用 Pandas 插入一个 Excel 公式? - How can I insert an excel formula using pandas when I save it as an excel file? 将工作表加载到Excel文件中,然后将其保存到另一个不同的Excel文件中 - Load sheet in an excel file and save it to another different excel file 将 .h5 (HDF5) 文件转换为 .zarr 格式时出现 TypeError - I'm getting a TypeError when converting .h5 (HDF5) file into .zarr format 如何在 csv 文件中将日期格式从 dd-mm-yyyy 更改为 dd/mm/yyyy - how to i change the format of date from dd-mm-yyyy to dd/mm/yyyy in a csv file 从Excel导入日期时如何在Python中保持格式(mm / dd / yyyy) - How to keep format (mm/dd/yyyy) in Python when importing dates from Excel OpenPyxl 将 python df 保存到具有多张纸的 excel 文件中,但是当我打开文件时,它会在第一张纸上打开 - OpenPyxl save python df into excel file with multiple sheets but when I open the file it opens on the first sheet 时间格式为 0:00:00 (h:mm:ss) 的 pandas datetime - pandas datetime with time format as 0:00:00 (h:mm:ss)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM