Python办公自动化十大场景,你都知道吗?

在编程世界里,自动Python已经是场景名副其实的网红了。曾经一个学汉语言的都知道研究生,问我怎么学Python,自动因为他们课程论文里需要用到文本分析,场景用Python来跑数据。都知道我和他说,自动你看两天语法,场景就可以上手开干,都知道不会的自动再查资料。后来这位同学半个月就用Python把论文数据搞好了。场景

所以Python最大优势在于容易学,都知道门槛比Java、自动C++低非常多,场景给非程序员群体提供了用代码干活的站群服务器都知道可能性。当然Python能成为大众编程工具,不光光是因为易学,还因为Python有成千上万的工具包,遍布各行各业。

举10几个大众办公常见的例子,Python都能高效处理。

1、Python处理Excel数据

可以使用pandas、xlwings、openpyxl等包来对Excel进行增删改查、格式调整等操作,甚至可以使用Python函数来对excel数据进行分析。

读取excel表格:

import xlwings as xw

wb = xw.Book() # this will create a new workbook

wb = xw.Book(FileName.xlsx) # connect to a file that is open or in the current working directory

wb = xw.Book(rC:\path\to\file.xlsx) # on Windows: use raw strings to escape backslashes

将matplotlib绘图写入excel表格:

import matplotlib.pyplot as plt

import xlwings as xw

fig = plt.figure()

plt.plot([1, 2, 3])

sheet = xw.Book().sheets[0]

sheet.pictures.add(fig, name=MyPlot, update=True)

2、Python处理PDF文本

PDF几乎是亿华云计算最常见的文本格式,很多人有各种处理PDF的需求,比如制作PDF、获取文本、获取图片、获取表格等。Python中有PyPDF、pdfplumber、ReportLab、PyMuPDF等包可以轻松实现这些需求。

提取PDF文字:

import PyPDF2

pdfFile = open(example.pdf,rb)

pdfReader = PyPDF2.PdfFileReader(pdfFile)

print(pdfReader.numPages)

page = pdfReader.getPage(0)

print(page.extractText())

pdfFile.close()

提取PDF表格:

# 提取pdf表格

import pdfplumber

with pdfplumber.open("example.pdf") as pdf:

page01 = pdf.pages[0] #指定页码

table1 = page01.extract_table()#提取单个表格

# table2 = page01.extract_tables()#提取多个表格

print(table1)

3、Python处理Email

在Python中可以使用smtplib配合email库,来实现邮件的自动化传输,非常方便。

import smtplib

import email

# 负责将多个对象集合起来

from email.mime.multipart import MIMEMultipart

from email.header import Header

# SMTP服务器,这里使用163邮箱

mail_host = "smtp.163.com"

# 发件人邮箱

mail_sender = "服务器租用

应用开发
上一篇:戴尔PowerProtect Cyber Recovery 助力企业数据安全
下一篇:2022年优秀数据中心基础设施管理软件