##作业
##制作一个自动生成请假条word文档的程序
##通过命令行提示用户输入姓名、请假原因
##自动生成代标题、正文内容的请假条
##日期自动填写今天日期
from docx import Document
import time
from docx.shared import Cm,Pt
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
year=time.localtime(time.time()).tm_year
month=time.localtime(time.time()).tm_mon
day=time.localtime(time.time()).tm_mday
#确定年月日
doc=Document()
name=input('请输入您的姓名:')
reason=input('请输入您请假的原因:')
#输入姓名盒轻雅原因
paragraph0=doc.add_paragraph('请假条')
paragraph0.alignment=WD_PARAGRAPH_ALIGNMENT.CENTER
#设置第一段标题居中
paragraph1=doc.add_paragraph('尊敬的老师您好:')
#对老师的敬语
paragraph2=doc.add_paragraph(f'我是{name},现在因为{reason}要去医院看病特向您请假,请您批准。')
paragraph2.paragraph_format.first_line_indent=Cm(0.75)
#第3段首行缩进0.75cm
paragraph3=doc.add_paragraph(f'{name}')
paragraph3.alignment=WD_PARAGRAPH_ALIGNMENT.RIGHT
paragraph4=doc.add_paragraph(f'{year}年{month}月{day}日')
paragraph4.alignment=WD_PARAGRAPH_ALIGNMENT.RIGHT
#第3,4段落款姓名和时间,设置右对齐
doc.save('请假条.docx')