从 streamlit 下载 python-pptx
download python-pptx from streamlit
我正在使用 python-pptx and streamlit。我正在从 python 创建一个 ppt,如下所示:
from pptx import Presentation
import streamlit as st
prs = Presentation()
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Hello, World!"
subtitle.text = "python-pptx was here!"
#prs.save('test.pptx') # This works, just saves it in the app path.
# But I want a clickable button, to be downloaded from the streamlit app.
# Therefore, I've tried to do this:
st.download_button(label = 'Download ppw', data = prs, file_name = 'my_power.ppt')
但我收到以下错误:
RuntimeError: Invalid binary data format: <class 'NoneType'>
复现要求:
安装 streamlit(pip install streamlit
)
安装 python-pptx (pip install python-pptx
)
我从 中获得灵感,我明白 你必须为你的 Presentation
对象生成一个二进制表示。
from pptx import Presentation
import streamlit as st
from io import BytesIO
prs = Presentation()
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Hello, World!"
subtitle.text = "python-pptx was here!"
# save the output into binary form
binary_output = BytesIO()
prs.save(binary_output)
st.download_button(label = 'Download ppw',
data = binary_output.getvalue(),
file_name = 'my_power.pptx')
我正在使用 python-pptx and streamlit。我正在从 python 创建一个 ppt,如下所示:
from pptx import Presentation
import streamlit as st
prs = Presentation()
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Hello, World!"
subtitle.text = "python-pptx was here!"
#prs.save('test.pptx') # This works, just saves it in the app path.
# But I want a clickable button, to be downloaded from the streamlit app.
# Therefore, I've tried to do this:
st.download_button(label = 'Download ppw', data = prs, file_name = 'my_power.ppt')
但我收到以下错误:
RuntimeError: Invalid binary data format: <class 'NoneType'>
复现要求:
安装 streamlit(pip install streamlit
)
安装 python-pptx (pip install python-pptx
)
我从 Presentation
对象生成一个二进制表示。
from pptx import Presentation
import streamlit as st
from io import BytesIO
prs = Presentation()
title_slide_layout = prs.slide_layouts[0]
slide = prs.slides.add_slide(title_slide_layout)
title = slide.shapes.title
subtitle = slide.placeholders[1]
title.text = "Hello, World!"
subtitle.text = "python-pptx was here!"
# save the output into binary form
binary_output = BytesIO()
prs.save(binary_output)
st.download_button(label = 'Download ppw',
data = binary_output.getvalue(),
file_name = 'my_power.pptx')