ValueError:无法将<pytime:9 11 =“”2017 =“”1:35:02 =“”am =“”>转换为Excel

时间:2017-09-11 05:48:12

标签: python excel

运行以下代码时出现此错误

current_time=MailItem.ReceivedTime
ws.cell(row=1, column=1).value = current_time

运行代码出错:

File "c:\Python27\lib\site-packages\openpyxl\cell\cell.py", line 294, in value
    self._bind_value(value)
  File "c:\Python27\lib\site-packages\openpyxl\cell\cell.py", line 201, in _bind_value
    raise ValueError("Cannot convert {0!r} to Excel".format(value))
ValueError: Cannot convert <PyTime:9/11/2017 1:35:02 AM> to Excel

1 个答案:

答案 0 :(得分:0)

看起来您应该手动将PyTime转换为字符串或Python日期/时间类型。可能你可以使用

time.ctime(int(current_time))

time.strftime("%#c", time.localtime(int(current_time)))

另见http://docs.activestate.com/activepython/2.4/pywin32/PyTime.html