从Outlook电子邮件中写入Excel文件
我用Python写了一些代码,使用win32com.client读取Outlook文件夹中的电子邮件。 我可以很容易地阅读它,把所有的逻辑build立起来,现在我想遍历所有的消息,写一个Excel文件。 这是我有一个问题。
我最近的尝试使用xlwt,但我打开使用任何东西。 我遇到的问题是,当我尝试从Outlook电子邮件发件人或date编写单元格时,出现以下错误:
exception:意外的数据types
有谁知道我可以解决这个问题/解决它吗?
我是否必须将.Sender,.Date实例转换为其他forms?
下面快速示例:
import win32com.client import xlwt outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") inbox = outlook.GetDefaultFolder(6) book = xlwt.Workbook(encoding="utf-8") sheet = book.add_sheet("New Sheet") for folder in inbox_folders: fold = folder.Items for messages in fold: date = fold.ReceivedTime sender = fold.Sender sheet.write(1,0,date) sheet.write(2,0,sender)
将sheet.write(2,0,sender)
replace为sheet.write(2,0,sender.Name)
或sheet.write(2,0,sender.Address).