运行以下代码时出现此错误
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
答案 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