问题标签 [python-pptx]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
680 浏览

python - Issues importing python-pptx on Linux (Ubuntu 17)

I am trying to import the python pptx library in a python programm. I installed it using pip before, which gave me the following output:

So this seems to be a success. But as I am trying to import the module using the following code:

It says No module named 'pptx'. It must have something to do with Linux since the same code works just fine on windows and the module seems to be installed correctly. I am using Python 3.5.3.

0 投票
1 回答
695 浏览

python-2.7 - Python-pptx折线图错误

这里的 Newb 刚刚进入 Python 并遇到了一个让我失望的问题。我有以下 Python 代码摘录,用于从现有模板创建 PPT 幻灯片。布局和占位符是正确的,但我无法使用下面列出的数据(x、y_in 和 y_out)运行它。任何帮助是极大的赞赏。

编译器吐出以下内容:

0 投票
1 回答
806 浏览

python - python-pptx 访问类别轴元素“tickLblSkip”和“tickMarkSkip”

我使用 pptx 创建了一个包含很多索引的折线图。我想告诉 ppt 使用此处显示的 XML 元素每 144 个索引标记刻度线:http: //python-pptx.readthedocs.io/en/latest/dev/analysis/cht-axes.html#related-schema-定义

不幸的是,我不知道如何调用该元素,也找不到任何帮助示例。有人能帮忙吗?

谢谢,杰瑞

0 投票
1 回答
867 浏览

python - 如何使用 pptx python 库更改 PPT 幻灯片上项目符号列表的缩进

我已经开始使用“pptx”库以编程方式生成一些基于 PPT 的报告。我们有一个公司模板,我将其用作基础。它包含一个带有单列格式的项目符号列表的母版幻灯片,如下所示(但每个级别的格式不同,例如项目符号类型和颜色。抱歉无法在此处分享实际图片):

项目符号列表格式

我想知道是否有一种方法可以改变各个级别的位置,就像我们从 MS PowerPoint 中的标尺(或右键单击 > 段落 > 缩进)中改变一样......?如果我更改项目符号列表的“级别”参数,它会从第一级更改为第二级以及所有格式。

但我只想将第一级向右移动几厘米。所以它看起来像:

项目符号列表向右移动

我知道一种明显的实现方法是添加具有所需格式的新母版幻灯片并使用它。但是,如果需要多次更改缩进,则很难为每个特定情况添加新的母版幻灯片。因此,我正在搜索是否有办法以编程方式使用“pptx”功能。到目前为止,我无法在“pptx”中找到这样的功能,但我可能错过了它,或者可能有一些解决方法。如果是这样,我很想知道。

0 投票
3 回答
3453 浏览

python - 如何将两个演示文稿 (pptx) 合并为一个主演示文稿?

我是创建 PPTX 演示文稿以呈现给客户的项目团队的一员。创建所有文件后,我们需要为每个演示文稿添加额外的幻灯片。每个演示文稿中的所有新幻灯片都是相同的。

以编程方式完成此任务的最佳方法是什么?

我不想使用 VBA,因为(据我所知)我必须打开每个演示文稿才能运行脚本。

我试过使用 python-pptx 库。但是文档指出:

“在一般情况下,将一张幻灯片从一个演示文稿复制到另一个演示文稿是相当困难的,因此在更多的积压工作被烧掉之前,这可能不会发生。”

我希望像下面这样的东西会起作用 -

有没有人成功地做这样的事情?

0 投票
1 回答
1626 浏览

python - 使用 Python pptx 获取图像文件名

我正在尝试编写一个脚本来打开用户指定的 ppt,读取它并找到图像文件名。我使用 python pptx 包,因为这让我实际上可以打开 ppt 文件。我试图浏览每张幻灯片并检查该幻灯片的图像,但我不知道如何使用 pptx 包执行此操作,并且该 imo 上的文档并不十分清楚。

因此,在深入研究文档之后,我发现这种工作可以完成:

这有效,但是它不返回正确的文件名。它返回 image.png 而文件名是 myfile.png

0 投票
1 回答
90 浏览

python - 无法将演示对象从 python-pptx 库转换为上传到 MS Graph API 服务端点

语境

我有一个 python 脚本,它使用 openpyxl 和 python-pptx 库分别生成工作簿和 PowerPoint。这些文件需要通过 Microsoft Graph API 作为八位字节流直接从虚拟内存上传。

障碍

由于该save_virtual_workbook方法返回内存中的工作簿,因此所有工作簿都适用于工作簿;但是我知道没有类似的方法,因此以可以通过该方法save_virtual_presentation流式传输的形式获取 Presentation 对象一直是一个挑战。io.BytesIO.read()

python.pptx文档说这Presentation.save(file)有效......

“其中file可以是文件的路径(字符串)或类似文件的对象。”

除了在执行 POC 时,我没有保存到本地文件系统的选项,所以我尝试了各种使用类似文件的对象的方法。除了下面的尝试之外,没有一个接近在对 MS Graph API 端点的 put 请求中被接受。

最近的小姐

在这种情况下,prs是在前面的代码中创建的 Presentation 对象,由于它是 556 行,我没有在这里包含它。

put 请求成功,但是保存到服务端点的文件是一个空的 pptx shell。我已经排除它prs本身是一个空的 pptx shell,所以我得出结论,这target_stream不是prs.

概括

有人可以通过建议如何将 Presentation 对象prs转换为我可以插入data=io.BytesIO.read(<<input>>)并成功上传到 MS Graph API 端点的东西来帮助我吗?我将非常感激!

0 投票
1 回答
378 浏览

python-pptx - 如何编辑python pptx图表的线条样式?

从 pptx 文档 ( http://python-pptx.readthedocs.io/en/latest/user/charts.html ),创建 XY 图表的代码是:

有人知道如何将系列样式更改为实线而不是标记吗?

0 投票
3 回答
1838 浏览

python - 如何在 Python 3 中将演示文稿保存到类似文件的对象中

Python 3 替换StringIO.StringIOio.StringIO. 我已经能够使用前者成功保存演示文稿,但它似乎不适用于后者。

上面的代码产生:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\site-packages\pptx\presentation.py", line 46, in save self.part.save(file) File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\site-packages\pptx\parts\presentation.py", line 118, in save self.package.save(path_or_stream) File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\site-packages\pptx\opc\package.py", line 166, in save PackageWriter.write(pkg_file, self.rels, self.parts) File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\site-packages\pptx\opc\pkgwriter.py", line 33, in write PackageWriter._write_content_types_stream(phys_writer, parts) File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\site-packages\pptx\opc\pkgwriter.py", line 47, in _write_content_types_stream phys_writer.write(CONTENT_TYPES_URI, content_types_blob) File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\site-packages\pptx\opc\phys_pkg.py", line 156, in write self._zipf.writestr(pack_uri.membername, blob) File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\zipfile.py", line 1645, in writestr with self.open(zinfo, mode='w') as dest: File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\zipfile.py", line 1349, in open return self._open_to_write(zinfo, force_zip64=force_zip64) File "C:\Users\mgplante\AppData\Local\Continuum\Anaconda2\envs\ppt_gen\lib\zipfile.py", line 1462, in _open_to_write self.fp.write(zinfo.FileHeader(zip64)) TypeError: string argument expected, got 'bytes'

有没有办法将演示文稿保存到 Python 3 中的类似文件的对象,或者我将不得不为这个项目使用 Python 2?

0 投票
1 回答
735 浏览

python-pptx - Why does saving a presentation to a file-like object produce a blank presentation?

As a response to this answer to a previous question of mine, I wrote the following short program to try and reproduce the problem.

This produced two pptx files.

The first, test.pptx, contained a single slide with the "Title Slide" layout and containing the string "asdf". The file size was 28 KB.

The second, bytes_test.pptx, when opened in PowerPoint, showed only a large grey box that said "Click to add first slide". The file size was 0.

Running on Windows 10 with Anaconda Python 3.6.1 and python-pptx 0.6.6

Why does this happen?