美文网首页
docx库笔记

docx库笔记

作者: lk_erzanml | 来源:发表于2021-01-31 00:02 被阅读0次
    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可以结束输入。
    
    

    相关文章

      网友评论

          本文标题:docx库笔记

          本文链接:https://www.haomeiwen.com/subject/gdozaktx.html