from docx import Document
from docx.enum.text import WD_ALIGN_PARAGRAPH
import sys,datetime
document=Document()#新建docx模板
title=input("Please input the title:\n")
p=document.add_heading(title, level=1)#添加标题
p.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.CENTER#居中
time=datetime.datetime.now().strftime("%Y-%m-%d-%H:%M:%S")
p1=document.add_heading(time+"\t\t\t\t\n\n\n",level=3)
p1.paragraph_format.alignment = WD_ALIGN_PARAGRAPH.RIGHT
print("Please input body:\n")
body=sys.stdin.read()
document.add_paragraph(body)#添加段落
time_name=time=datetime.datetime.now().strftime("%Y%m%d%H%M%S")
document.save("diary"+time+".docx")#保存
#sys.stdin.read()输入几行,便读出几行,但是空行之后不读。
#sys.stdin.readlines()输入几行,读几行,空行也读。
#sys.stdin.readline()只读一行。
#ctrl+d可以结束输入。
网友评论