如何从数据块显示和下载 pptx 文件?
How to display and download a pptx file from databricks?
我使用 Python 在数据块中使用实用程序脚本生成了一个 power point deck。我现在想在内核中访问该文件,但由于甲板上的图像,它显示了奇怪的符号。如何更正此输出牌组图像的语句?
#access file
dbutils.fs.head('file:/dbfs/user/test.pptx')
Out: 'PK\x03\x04\x14\x00\x00\x00\x08\x00D�lOƯ�g�\x01\x00\x00�\x0c\x00\x00\x13\x00\x00\x00[Content_Types].xml͗�N�0\x10��<E�K\x0e�q�\x175��rb�\x04<�I����-ϴзg�.��R�\n_\x12�3���\'Q4霼�:\x1a�GeM�l��$\x02��B�A���]�\x0e�\x08I�Bjk K&��Iw�s7q�\x11\x17\x1b��!�;\x16\x02�!
How to display a pptx file from databricks?
使用以下代码显示数据块中的 pptx 文件:
from pptx import Presentation
prs = Presentation('/dbfs/myfolder/BRK4024.pptx')
for slide in prs.slides:
for shapes in slide.shapes:
print( shapes.shape_type )
print( '----------------' )
if shapes.has_text_frame:
print( shapes.text )
笔记本样本:
注意: 在输出中你会看到 ("PlaceHolders", "AutoShapes", "Pictures") 因为 python-pptx 不支持 SmartArt。您需要手动将内容插入 placeholder/AutoShapes/Pictures,这将是构建 python.
的开销任务
示例: Sample code - add an image in every Powerpoint slide using python-pptx
How to download a pptx file from databricks?
您可以使用 databricks cli 将文件从 databricks 文件系统下载到本地计算机,如下所示;
dbfs cp dbfs:/myfolder/BRK4024.pptx A:DataSet\
示例: 因为我在 dbfs 上的 myfolder 中有一个示例 BRK4024.pptx 文件,所以我正在使用 databricks cli 命令复制到本地计算机文件夹名称(A:数据集)
希望对您有所帮助。
只需补充回答部分问题 How to display a pptx file from databricks?
。
当然,我看到@CHEEKATLAPRADEEP-MSFT 已经回答了如何使用 python-pptx
提取 pptx 文件的文本内容并显示在数据块笔记本中。
但是,如果你想像博客Converting presentation slides to HTML blog post with images
那样在databricks notebook中将pptx文件的整个幻灯片显示为图像,在databricks notebook中是不可能的,原因如下。
- Databricks 在 Linux 中是 运行,因此您无法通过
win32
api 将 pptx 文件转换为图像以调用 MS PowerPoint 应用程序。
- 现有的pptx转图片方案需要在运行机器上安装
LibraOffice
,恐怕在Linux[=41]上做不到=] 用于云数据块。由于 https://github.com/scanny/python-pptx/issues/348 问题,python-pptx
无法进行转换。甚至没有任何Python包可以单独完成。
如果您使用的数据块是私人机器,您可以尝试按照数据块文档Use Notebooks
的SO线程How to convert pptx files to jpg or png (for each slide) on linux? or the code from https://github.com/innaky/pptx-to-images/blob/master/pptx-to-images.py to get the images of slides of a pptx file, then you can refer to the section Display images
来显示它们。
当然,您也可以将本地pptx文件转换成的图片上传到云端数据块,然后进行显示。但是完全在云数据块上自动完成这些似乎是不可能的。
我使用 Python 在数据块中使用实用程序脚本生成了一个 power point deck。我现在想在内核中访问该文件,但由于甲板上的图像,它显示了奇怪的符号。如何更正此输出牌组图像的语句?
#access file
dbutils.fs.head('file:/dbfs/user/test.pptx')
Out: 'PK\x03\x04\x14\x00\x00\x00\x08\x00D�lOƯ�g�\x01\x00\x00�\x0c\x00\x00\x13\x00\x00\x00[Content_Types].xml͗�N�0\x10��<E�K\x0e�q�\x175��rb�\x04<�I����-ϴзg�.��R�\n_\x12�3���\'Q4霼�:\x1a�GeM�l��$\x02��B�A���]�\x0e�\x08I�Bjk K&��Iw�s7q�\x11\x17\x1b��!�;\x16\x02�!
How to display a pptx file from databricks?
使用以下代码显示数据块中的 pptx 文件:
from pptx import Presentation
prs = Presentation('/dbfs/myfolder/BRK4024.pptx')
for slide in prs.slides:
for shapes in slide.shapes:
print( shapes.shape_type )
print( '----------------' )
if shapes.has_text_frame:
print( shapes.text )
笔记本样本:
注意: 在输出中你会看到 ("PlaceHolders", "AutoShapes", "Pictures") 因为 python-pptx 不支持 SmartArt。您需要手动将内容插入 placeholder/AutoShapes/Pictures,这将是构建 python.
的开销任务示例: Sample code - add an image in every Powerpoint slide using python-pptx
How to download a pptx file from databricks?
您可以使用 databricks cli 将文件从 databricks 文件系统下载到本地计算机,如下所示;
dbfs cp dbfs:/myfolder/BRK4024.pptx A:DataSet\
示例: 因为我在 dbfs 上的 myfolder 中有一个示例 BRK4024.pptx 文件,所以我正在使用 databricks cli 命令复制到本地计算机文件夹名称(A:数据集)
希望对您有所帮助。
只需补充回答部分问题 How to display a pptx file from databricks?
。
当然,我看到@CHEEKATLAPRADEEP-MSFT 已经回答了如何使用 python-pptx
提取 pptx 文件的文本内容并显示在数据块笔记本中。
但是,如果你想像博客Converting presentation slides to HTML blog post with images
那样在databricks notebook中将pptx文件的整个幻灯片显示为图像,在databricks notebook中是不可能的,原因如下。
- Databricks 在 Linux 中是 运行,因此您无法通过
win32
api 将 pptx 文件转换为图像以调用 MS PowerPoint 应用程序。 - 现有的pptx转图片方案需要在运行机器上安装
LibraOffice
,恐怕在Linux[=41]上做不到=] 用于云数据块。由于 https://github.com/scanny/python-pptx/issues/348 问题,python-pptx
无法进行转换。甚至没有任何Python包可以单独完成。
如果您使用的数据块是私人机器,您可以尝试按照数据块文档Use Notebooks
的SO线程How to convert pptx files to jpg or png (for each slide) on linux? or the code from https://github.com/innaky/pptx-to-images/blob/master/pptx-to-images.py to get the images of slides of a pptx file, then you can refer to the section Display images
来显示它们。
当然,您也可以将本地pptx文件转换成的图片上传到云端数据块,然后进行显示。但是完全在云数据块上自动完成这些似乎是不可能的。