# 前期准备:导入包
import xlrd
from docx import Document
# 一、打开excel文件
data = xlrd.open_workbook('D://Python//中国2019年GDP.xls')
# 打开名为“GDP2019”的工作表
st = data.sheet_by_name('GDP2019')
# 二、复制excel中第2行第2列的值
China_GDP_2019 = st.cell(1, 1).value
# 三、新建空白文档
document = Document()
# 四、写正文
document.add_paragraph('2019年,中国GDP为' + str(China_GDP_2019) + '万亿元。')
# 五、保存文件
document.save('D://Python//中国GDP2019.docx')
办公自动化:8行代码自动生成一篇文章
最新推荐文章于 2024-06-11 18:07:33 发布