尝试从Win32com Python bib获取ReceivedTime时出错



我在保存获取outlook邮件receivedTime的代码时收到一个错误。但我不知道有什么可能出错。请参阅以下错误:

Exception has occurred: TypeError
Excel does not support timezones in datetimes. The tzinfo in the datetime/time object must be set to None.

有人能帮我吗?

代码:

from datetime import datetime
from operator import index
from typing import Pattern
import win32com.client
import openpyxl
from openpyxl import Workbook
from openpyxl.styles import Font, Color, PatternFill, fills, Border, Side

outlook = win32com.client.Dispatch("outlook.application")
mapi = outlook.GetNamespace("MAPI")
account = [i for i in mapi.Accounts][0]
inbox = mapi.GetDefaultFolder(6)
test_folder = inbox.Folders["TravelAlertReport"]
items = test_folder.Items
wb= Workbook()
planilha = wb.worksheets[0]
ws=wb["Sheet"]
#Header
list_header = ["Status", "Level", "Location", "Category", "Date", "Month", "Year", "Relevant?(Yes/No)", "Justification", "Used by TST", "Learning Required?"]
#Rows' content    
for index,item in enumerate(items):

#Time
date_time = item.ReceivedTime
ws.cell(row=index+2, column = 5).value = date_time
wb.save("Report.xlsx")

MailItem.ReceivedTime属性返回一个Date,指示接收项目的日期和时间。

尝试使用代码中的任何其他日期对象来查看是否存在任何差异,例如:

'Insert Today's Date
Range("A1").Value = Date

'Insert A Date (mm/dd/yyyy)
Range("B1") = #1/28/2019#

如果该代码有效,那么您需要按照Excel理解的方式格式化日期对象。Format函数可以帮助实现这一点。

相关内容

  • 没有找到相关文章

最新更新