excel写到Word

from docx import Document
import pandas as pd
import matplotlib.pyplot as plt
tata2=pd.read_excel("jjh.xlsx")#打开Excel
tata2.sort_values(by="Age",inplace=True,ascending=False)#对age里的数据排序
plt.bar(tata2.Name,tata2.Age,color="orange")#柱状图显示name和age
plt.title("jjh",fontsize=18)
plt.xlabel("tata1")
plt.ylabel("values")#两个坐标轴
plt.xticks(tata2.Name,rotation="90")#字体旋转90度
plt.tight_layout()#紧凑型
image="data.jpg"
plt.savefig(image)
document=Document()
first_student=tata2.iloc[0,:]["Name"]
first_score=tata2.iloc[0,:]["Score"]
p=document.add_paragraph("分数排名第一的学生是")
p.add_run(str(first_student)).bold=True
p.add_run(",他的分数是")
p.add_run(str(first_score)).bold=True
p=document.add_paragraph(f"总共有{len(tata2.Name)}")
table=document.add_table(rows=len(tata2.Name)+1,cols=2)
document.add_heading("周报告",level=1)
table.style="LightShading-Accent1"
table.cell(0,0).text="学生名称"
table.cell(0,1).text="学生分数"
for i,(index,row) in enumerate(tata2.iterrows()):
    table.cell(i+1,0).text=str(row['Name'])
    table.cell(i+1,1).text = str(row['Score'])
document.add_picture(image)
document.save("s.docx")
print("done")

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值