设计一个期末成绩总结的word文件
from docx import Document
from docx.shared import Pt, Cm, RGBColor
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
from docx.enum.table import WD_CELL_VERTICAL_ALIGNMENT
import openpyxl
doc = Document()
doc.add_picture('files/car.png', width=Pt(20), height=Pt(20))
h1 = doc.add_heading(level=1)
h1.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
run1 = h1.add_run('<<img1>>', style='Title Char')
if '<<img1>>' in h1.text:
h1.text = h1.text.replace('<<img1>>','')
run1 = h1.add_run('希望大学', style='Title Char')
run1.add_picture('files/car.png', width=Pt(40), height=Pt(40))
run1.font.size = Pt(40)
run1.font.color.rgb = RGBColor(255, 0, 0)
run1.font.bold = True
run1.font.shadow = True
h1.paragraph_format.space_before = Pt(100)
h2 = doc.add_heading(level=1)
h2.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
run2 = h2.add_run('期末成绩总结', style='Title Char')
run2.font.size = Pt(20)
h2.paragraph_format.space_after = Pt(80)
tabel1 = doc.add_table(3, 2, style='Medium Shading 2')
tabel1.style.font.size = Pt(20)
tabel1.style.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
tabel1.cell(0, 0).text = '科目'
tabel1.cell(0, 1).text = ':_____________________'
tabel1.cell(1, 0).text = '姓名'
tabel1.cell(1, 1).text = ':_____________________'
tabel1.cell(2, 0).text = '时间'
tabel1.cell(2, 1).text = ':_____________________'
rows = tabel1.rows
for row in rows:
row.height = Pt(100)
for cell in row.cells:
cell.vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.CENTER
p1 = doc.add_paragraph()
run3 = p1.add_run(
'考试后,同学们最为关心的莫过于各门功课的分数了。其实分数只不过是对你这一阶段努力的一个评价,考完后不是盯着它,关键是要弄清失分的原因,及时弥补这一阶段的不足。学习的过程,也就是不断发现问题并解决问题的过程。成绩不埋想的背后,就是问题的暴露,我们必须立即总结反思,采取措施,加以补救,才能在未来的期末考试、中考、高考中创造辉煌。',
style='Strong')
run3.font.name = '宋体'
run3.font.size = Pt(18)
run3.font.color.rgb = RGBColor(105, 105, 105)
p1.paragraph_format.first_line_indent = Pt(36)
p2 = doc.add_paragraph()
run4 = p2.add_run('作为考试反思,首先反思的就是平时的学习态度。如果在考试中,记忆性的题日失分过多,特别是记忆性偏重的学科失分多(如生物、地理和语文、英语的基础题),那显然就是投入不足,学习态度的向题。如果许多简单的知识应用中,出错较多,运算能力欠缺,即是反映平时训练不够,这也是学习态度有问题。反思自己平时是否自觉地进行学习、复习;是否心存侥辛心理,认为平时拖拉点没事,只要考试前几天,认真一点就可以应付。反思自己是否盲目的学习,有些同学是做一天和尚敲一天钟,混过去就算了;有些司学每天有很多的计划与目标,而一天下来没有一个目标能实现。反思自己的学习是否扎实,对于新知识是否只是停留在了解、 识记的层次,有没有进行掌握和运用。大多数同学对知识的理解处于一知半解状态,在解题时不知如何下籍。其实,学习态度是决定成绩好差的前提条件,要想取得好的成绩,必须要有一个良好的学习可惯,端正的学习态度。',style='Body Text Char')
run4.font.size = Pt(16)
run4.font.color.rgb = RGBColor(0, 0, 0)
p2.paragraph_format.first_line_indent = Pt(32)
p3 = doc.add_paragraph()
run5 = p3.add_run(
'其次同学们应反思一下对考试技巧的把握。每次考试总能发现一部分学生缺之一定的考试技巧,如:觉得考试时间不够,字迹潦草,连自己都看不清;答案亏在密封线内,被装订看不到;甚至有学生独辟蹊径,先从最后一道题开始做等等。作为考试的基本常识:先易后难,规范书亏,合理分配时间这些可惯,都应该在平时单元测试中要锻炼出来的。',
style='Body Text Char')
run5.font.name = '宋体'
run5.font.size = Pt(16)
run5.font.color.rgb = RGBColor(0, 0, 0)
p3.paragraph_format.first_line_indent = Pt(32)
h3 = doc.add_heading(level=1)
h3.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
run6 = h3.add_run('期末成绩表', style='Title Char')
run6.font.size = Pt(20)
h3.paragraph_format.space_after = Pt(20)
wb = openpyxl.open('files/学生信息.xlsx')
stu_sheet = wb['students']
i = 1
tabel2 = doc.add_table(49, 4, style='Medium Shading 2')
tabel2.style.font.size = Pt(16)
tabel2.style.paragraph_format.alignment = WD_PARAGRAPH_ALIGNMENT.CENTER
rows = tabel2.rows
for row in rows:
row.height = Pt(20)
for j in range(1,5):
row.cells[j-1].vertical_alignment = WD_CELL_VERTICAL_ALIGNMENT.CENTER
row.cells[j-1].text =str(stu_sheet.cell(i,j).value)
i += 1
doc.add_page_break()
p4 = doc.add_paragraph()
run7 = p4.add_run('总人数:'+str(stu_sheet.max_row-1),style='Strong')
run7.font.name = '宋体'
run7.font.size = Pt(18)
run7.font.color.rgb = RGBColor(205,133,63)
p5 = doc.add_paragraph()
max_score=0
for i in range(2,49):
if int(stu_sheet.cell(i,4).value)>max_score:
max_score=stu_sheet.cell(i,4).value
run8 = p5.add_run('最高分:'+str(max_score),style='Strong')
run8.font.name = '宋体'
run8.font.size = Pt(18)
run8.font.color.rgb = RGBColor(205,133,63)
p6 = doc.add_paragraph()
sum_score=0
for i in range(2,49):
sum_score +=int(stu_sheet.cell(i,4).value)
n_score=float(sum_score/int(stu_sheet.max_row-1))
n_score='%.2f'%n_score
run9 = p6.add_run('平均分:'+str(n_score),style='Strong')
run9.font.name = '宋体'
run9.font.size = Pt(18)
run9.font.color.rgb = RGBColor(205,133,63)
p7 = doc.add_paragraph()
count=0
for i in range(2,49):
if stu_sheet.cell(i,4).value>60:
count +=1
n_jige=float(count/(stu_sheet.max_row-1)*100)
n_jige='%.2f'%n_jige
run10 = p7.add_run('及格率:'+str(n_jige)+'%',style='Strong')
run10.font.name = '宋体'
run10.font.size = Pt(18)
run10.font.color.rgb = RGBColor(205,133,63)
doc.save('files/zuoye.docx')
ge)+'%',style='Strong')
run10.font.name = '宋体'
run10.font.size = Pt(18)
run10.font.color.rgb = RGBColor(205,133,63)
doc.save('files/zuoye.docx')