github star gitee star atomgit star PyPI Downloads AI编程 AI交流群

大家好,这里是程序员晚枫,正在all in AI编程实战

第17讲:AI自动化办公——让AI帮你处理文档

为什么AI+办公?

AI能帮你做重复性工作:

  • 批量生成Word报告
  • 自动提取Excel关键数据
  • 智能总结PDF内容
  • 自动回复邮件

1、AI + Excel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from openai import OpenAI
import office

client = OpenAI(api_key="你的Key", base_url="https://api.deepseek.com")

# 读取Excel数据
data = office.excel.read_excel("销售数据.xlsx")

# 让AI分析数据
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "你是数据分析专家"},
{"role": "user", "content": f"分析以下销售数据,给出总结和建议:\n{data}"}
]
)

analysis = response.choices[0].message.content
print(analysis)

2、AI + Word

1
2
3
4
5
6
7
8
9
10
11
# AI生成报告,写入Word
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "user", "content": "写一份2025年度工作总结,包含:完成项目、学习成长、明年计划"}
]
)

report = response.choices[0].message.content
# 用python-office写入Word
office.word.create_word(report, "年度总结.docx")

3、AI + PDF

1
2
3
4
5
6
7
8
9
10
11
12
13
# 提取PDF文本,让AI总结
text = office.pdf.read_pdf("合同.pdf")

response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "你是法律顾问,擅长分析合同"},
{"role": "user", "content": f"请总结这份合同的关键条款和风险点:\n{text}"}
]
)

summary = response.choices[0].message.content
print(summary)

4、AI + PPT

1
2
3
4
5
6
7
8
9
10
11
# AI生成PPT大纲
response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "user", "content": "生成一个产品发布会的PPT大纲,5个章节,每章3个要点"}
]
)

outline = response.choices[0].message.content
# 用python-office创建PPT
office.ppt.create_ppt(outline, "发布会.pptx")

5、批量处理实战

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
from openai import OpenAI
import office

client = OpenAI(api_key="你的Key", base_url="https://api.deepseek.com")

# 批量总结文件夹里的所有PDF
pdf_dir = "合同文件"
for filename in os.listdir(pdf_dir):
if filename.endswith(".pdf"):
filepath = os.path.join(pdf_dir, filename)
text = office.pdf.read_pdf(filepath)

response = client.chat.completions.create(
model="deepseek-chat",
messages=[
{"role": "system", "content": "用3句话总结合同要点"},
{"role": "user", "content": text[:2000]}
]
)

summary = response.choices[0].message.content
print(f"📄 {filename}: {summary}\n")

6、常见问题

Q:PDF太长怎么办?
A:分段读取,每段单独让AI总结,最后汇总。

Q:AI生成的内容格式不对?
A:在prompt里明确指定格式要求。

下讲预告

学会了AI自动化办公,下一讲我们学 AI图像处理——让AI帮你处理图片。

敬请期待!


程序员晚枫专注AI编程培训,小白看完他和图灵社区合作的教程《30讲 · AI编程训练营》就能上手做AI项目。

前3讲可以试听,试听链接:https://www.bilibili.com/cheese/play/ss982042944