import streamlit as st from docx import Document from docx.shared import Inches from docxtpl import DocxTemplate, InlineImage from docx.shared import Mm, Inches import datetime import io document = Document() document.add_heading('Document Title', 0) p = document.add_paragraph('A plain paragraph having some ') p.add_run('bold').bold = True p.add_run(' and some ') p.add_run('italic.').italic = True document.add_heading('Heading, level 1', level=1) document.add_paragraph('Intense quote', style='Intense Quote') # Create in-memory buffer file_stream = io.BytesIO() # Save the .docx to the buffer document.save(file_stream) # Reset the buffer's file-pointer to the beginning of the file file_stream.seek(0) st.download_button( label="Download report here", data=file_stream, file_name="SEAO Fold 4_Flip 4 Quality Monitoring (" + datetime.datetime.now().strftime("%#d %b") + ").docx", mime='application/vnd.openxmlformats-officedocument.wordprocessingml.document', )