excel表格是领导的每月值班排班,是一个人一个人排的,需要把这种excel换成word表格中这种每天的值班表,通过python代码能实现吗?
#############################################
#pandas绘制柱状图
import pandas as pd
import matplotlib.pyplot as plt
students = pd.read_excel('people.xlsx')
students.sort_values(by= 'Score',inplace=True, ascending=False )
#直接使用plt.bar( )绘制柱状图
plt.bar(students.Name,students.Score,color='orange')
#设置标题、x轴名称与y轴名称,fontsize 设置字号
plt.title('Student Score',fontsize=16)
plt.xlabel('Name')
plt.ylabel('Score')
#因为x轴字体太长,利用rotation 将其旋转90度,方便显示
plt.xticks(students. Name, rotation='90')
#紧凑型布局(因为x轴文字比较长,为了让其显示全,使用紧凑型布局)
plt.tight_layout( )
plt.show( )
#添加中文字体支持
from matplotlib.font_manager import FontProperties
font = FontProperties(fname=r"字体的路径,以.ttc结尾", size=16)
plt.title('学生分数', fontproperties=font)
plt.xlabel('名字', fontproperties=font, fontsize=14)
plt.ylabel('成绩', fontproperties=font, fontsize=14)
#############################################
#pandas绘制叠加柱状图
import pandas as pd
import matplotlib.pyplot as plt
users = pd.read_excel('people.xlsx')
#新计算出一个总量,用于排序
users['Total'] = users['Jan']+users['Feb']+users['Mar']
#排序
users.sort_values(by='Total',inplace=True )
#水平的叠加柱状图,barh中的h表示horizontal水平的,
#利用stacked 就可以实现叠加形式
users.plot.barh(x='Name', y=['Jan','Feb','Mar'], stacked=True )
plt.tight_layout( )
plt.show( )
可以使用Python代码实现将固定格式的Excel表格转换为固定格式的Word表格。以下是一个简单的实现步骤:
from docxtpl import DocxTemplate
from openpyxl import load_workbook
import os
def replace(obj):
if obj is None:
obj = ''
return obj
wb = load_workbook(r"C:\Users\MSI2\data(1).xlsx")
ws = wb['Sheet1']
contexts = []
for row in range(2, ws.max_row + 1):
name = ws["A" + str(row)].value
c_name = ws["B" + str(row)].value
code = ws["C" + str(row)].value
num = ws["D" + str(row)].value
time = ws["E" + str(row)].value
time = str(time)[:-9]
money = ws["F" + str(row)].value
address = ws["G" + str(row)].value
replace_peo = ws["H" + str(row)].value
context = {"name": name, "c_name": c_name, "code": code, "num": num, "time": time,
"money": money, "address": address, "replace_peo": replace_peo}
contexts.append(context)
os.mkdir("./所有合同")
for context in contexts:
tpl = DocxTemplate(r"C:\Users\MSI2\A公司(1).docx")
tpl.render(context)
tpl.save("./所有合同/{}的劳动合同.docx".format(context["name"]))
以上代码将根据Excel表格的数据填入到指定的Word模板中,并生成对应的Word文档保存在指定的文件夹内。
请注意替换代码中的文件路径和文件名,使其与你的实际情况相符。
可以是可以,但是这是苦力。
你得掌握分解动作,如何循环从excel得到数据
如何填充到word表格里
你每一步分解出来去做,做不出来,可以帮你。丢一个完整的需求问怎么做没法回答。