- 0
- 0
- 0
- 打赏
位置: 首页 >文章
Python 办公自动化主要Excel,PPT,Word,邮件,再加上数据分析、爬虫等技能
pip install xlwings
pip install openpyxl
实现对Excel表格的读、写、格式调整、自动化图表生成等
以下用xlwings进行表格的自动写入
import xlwings as xw
# 打开Excel应用程序
app = xw.App(visible=False, add_book=False)
# 打开Excel工作簿
wb = xw.Book('test.xlsx')
# 选择要操作的工作表
sheet = wb.sheets['Sheet1']
# 写入数据
sheet.range('A1').value = 'Hello'
# 关闭工作簿和Excel应用程序
wb.save()
wb.close()
app.quit()
pip install python-pptx
对PPT幻灯片的读、写、改、删除等操作
以下对幻灯片的写入操作
from pptx import Presentation
from pptx.util import Inches
# 打开PPT文件
prs = Presentation('test.pptx')
# 获取要插入图片的幻灯片
slide = prs.slides[0]
# 插入图片
pic = slide.shapes.add_picture('test.jpg', Inches(1), Inches(1))
# 保存修改后的PPT文件
prs.save('test.pptx')
pip install python-docx
对Word文档的读、写、改、删除等操作
以下对word写入,修改
from docx import Document
from docx.shared import Inches
# 打开Word文档
doc = Document('test.docx')
# 获取要插入表格的段落
para = doc.add_paragraph()
# 插入表格
table = para.add_table(rows=3, cols=3)
# 修改表格内容
table.cell(0, 0).text = 'A1'
table.cell(0, 1).text = 'A2'
table.cell(1, 0).text = 'A3'
table.cell(1, 1).text = 'A4'
# 保存修改后的Word文档
doc.save('test.docx')
pip install smtplib
对邮件的自动发送、接收、附件添加等操作
import smtplib
from email.mime.text import MIMEText
# 发件人邮箱
sender = '发件人邮箱'
# 收件人邮箱
receiver = '收件人邮箱'
# 邮件内容
msg = MIMEText('Hello, world!')
msg['Subject'] = '邮件测试'
msg['From'] = sender
msg['To'] = receiver
# 发送邮件
smtp = smtplib.SMTP('smtp.example.com')
smtp.login(sender, 'password')
smtp.sendmail(sender, [receiver], msg.as_string())
smtp.quit()
pip install pandas
pip install numpy
pip install matplotlib
import pandas as pd
import matplotlib.pyplot as plt
# 读取csv文件
df = pd.read_csv('文件路径')
# 数据清洗
df = df.dropna()
# 数据分析
avg_value = df['value'].mean()
# 数据可视化
plt.plot(df['date'], df['value'])
plt.show()
pip install requests
pip install scrapy
pip install BeautifulSoup
...
以下关于爬虫的文章
https://www.ormcc.com/tag/6
转载:欢迎来到本站,转载请注明文章出处https://www.ormcc.com ,欢迎加入技术讨论群599606903
上一篇:python定时任务,定时实现发邮件,定时备份...
下一篇:CSS跳动的文字
ormcc
一个爱捣鼓的程序员
IP访问121772次,运行1480天
微信支付宝