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

Error while trying to get ReceivedTime from Win32com Python bib

我在尝试保存获取 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 属性 returns 表示收到项目的日期和时间的日期。

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

'Insert Today's Date
Range("A1").Value = Date
  
'Insert A Date (mm/dd/yyyy)
Range("B1") = #1/28/2019#

如果该代码有效,那么您需要以 Excel 理解的方式格式化日期对象。 Format 函数可以提供帮助。