hongaik commited on
Commit
54b3a40
1 Parent(s): b6722b1

initial test

Browse files
Files changed (4) hide show
  1. app.py +12 -3
  2. report_template.docx +0 -0
  3. requirements.txt +2 -1
  4. test.py +35 -0
app.py CHANGED
@@ -4,6 +4,7 @@ from docxtpl import DocxTemplate, InlineImage
4
  from docx.shared import Mm, Inches
5
  import datetime
6
  from datetime import timedelta, date
 
7
  # from utils import *
8
 
9
  ########## Title for the Web App ##########
@@ -268,13 +269,21 @@ if len(uploaded_files) > 0:
268
 
269
  context2 = {**context, **flip4_dict, **fold4_dict}
270
  doc.render(context2)
271
- #results = doc.save("SEAO Fold 4_Flip 4 Quality Monitoring (" + datetime.datetime.now().strftime("%#d %b") + ").docx")
 
 
 
 
 
 
 
 
272
 
273
  st.download_button(
274
  label="Download report here",
275
- data=doc.docx,
276
  file_name="SEAO Fold 4_Flip 4 Quality Monitoring (" + datetime.datetime.now().strftime("%#d %b") + ").docx",
277
- mime='application/vnd.openxmlformats-officedocument.wordprocessingml.document',
278
  )
279
 
280
 
 
4
  from docx.shared import Mm, Inches
5
  import datetime
6
  from datetime import timedelta, date
7
+ import io
8
  # from utils import *
9
 
10
  ########## Title for the Web App ##########
 
269
 
270
  context2 = {**context, **flip4_dict, **fold4_dict}
271
  doc.render(context2)
272
+
273
+ # Create in-memory buffer
274
+ file_stream = io.BytesIO()
275
+ # Save the .docx to the buffer
276
+ doc.save(file_stream)
277
+ # Reset the buffer's file-pointer to the beginning of the file
278
+ file_stream.seek(0)
279
+
280
+ #doc.save("SEAO Fold 4_Flip 4 Quality Monitoring (" + datetime.datetime.now().strftime("%#d %b") + ").docx")
281
 
282
  st.download_button(
283
  label="Download report here",
284
+ data=file_stream,
285
  file_name="SEAO Fold 4_Flip 4 Quality Monitoring (" + datetime.datetime.now().strftime("%#d %b") + ").docx",
286
+ mime='application/vnd.openxmlformats-officedocument.wordprocessingml.document'
287
  )
288
 
289
 
report_template.docx DELETED
Binary file (32.7 kB)
 
requirements.txt CHANGED
@@ -3,4 +3,5 @@ docxtpl
3
  pandas==1.2.4
4
  datetime
5
  xlrd==1.0.0
6
- openpyxl
 
 
3
  pandas==1.2.4
4
  datetime
5
  xlrd==1.0.0
6
+ openpyxl
7
+ io
test.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from docx import Document
3
+ from docx.shared import Inches
4
+ from docxtpl import DocxTemplate, InlineImage
5
+ from docx.shared import Mm, Inches
6
+ import datetime
7
+ import io
8
+
9
+ document = Document()
10
+
11
+ document.add_heading('Document Title', 0)
12
+
13
+ p = document.add_paragraph('A plain paragraph having some ')
14
+ p.add_run('bold').bold = True
15
+ p.add_run(' and some ')
16
+ p.add_run('italic.').italic = True
17
+
18
+ document.add_heading('Heading, level 1', level=1)
19
+ document.add_paragraph('Intense quote', style='Intense Quote')
20
+
21
+ # Create in-memory buffer
22
+ file_stream = io.BytesIO()
23
+ # Save the .docx to the buffer
24
+ document.save(file_stream)
25
+ # Reset the buffer's file-pointer to the beginning of the file
26
+ file_stream.seek(0)
27
+
28
+
29
+ st.download_button(
30
+ label="Download report here",
31
+ data=file_stream,
32
+ file_name="SEAO Fold 4_Flip 4 Quality Monitoring (" + datetime.datetime.now().strftime("%#d %b") + ").docx",
33
+ mime='application/vnd.openxmlformats-officedocument.wordprocessingml.document',
34
+ )
35
+