python - 使用 Python 将 Outlook 电子邮件正文复制到 Excel
问题描述
我在 Outlook 电子邮件正文中有 3 个表格。Outlook 电子邮件可以用唯一的主题来识别,我希望将以上 3 个表格粘贴到 Excel 工作表的每个单元格中,而不是单个单元格中。
我试过下面的python代码,它将整个内容粘贴为单个单元格中的文本。
import win32com.client
import os
import openpyxl
# Call a Workbook() function of openpyxl
# to create a new blank Workbook object
wb = openpyxl.Workbook()
# Get workbook active sheet
# from the active attribute
sheet = wb.active
# Cell objects also have row, column
# and coordinate attributes that provide
# location information for the cell.
# Note: The first row or column integer
# is 1, not 0. Cell object is created by
# using sheet object's cell() method.
c1 = sheet.cell(row = 1, column = 1)
outlook=win32com.client.Dispatch("Outlook.Application").GetNameSpace("MAPI")
inbox=outlook.GetDefaultFolder(6) #Inbox default index value is 6
message=inbox.Items
message2=message.GetLast()
subject=message2.Subject
body=message2.body
date=message2.senton.date()
sender=message2.Sender
attachments=message2.Attachments
for m in message:
if m.Subject=="Sample Change Log ":# here in my requirement i will change the dates
print(m.body)
# writing values to cells
c1.value = m.body
wb.save("D:\\demo.xlsx")
解决方案
c1 = sheet.cell(row = 1, column = 1)
您只指定了一个单元格,因此它将所有数据放入一个单元格中。
如果您希望它位于多个位置,请为每封电子邮件指定一个单元格位置
推荐阅读
- django - Django Admin - 调用 change_view 进行内联
- python - 识别滚动异常值并通过回填时间序列数据替换它们 - Pandas
- ios - 应用程序打开时如何使推送通知出现在前台
- javascript - 为什么拼接方法不起作用并在 TypeScript 中删除数组上的项目
- google-sheets - 重新加载页面时 importdata() 函数失败
- python - 将不带引号的列名提供给 R 函数 [rpy2]
- ionic-framework - 由于 Ionic 4 中的路径问题,图像未加载到离子服务上
- c++ - C++:无法访问声明的受保护成员:
- oracle - 当我尝试在存储过程中声明目录时,我得到“PLS-00103:遇到符号“CREATE”...”
- javascript - 我可以将 EventListener 添加到我在 innerHTML 中创建的类中吗