我正在编写代码,以找出现有PowerPoint演示文稿中存在的占位符数量。但是由于某种原因,我无法加载要调整的边值。我在这里错过了一些东西。有人可以指导我吗?
我阅读了文档,看到大多数示例都添加了一行
slide=prs.slides.add_slide(prs.slide_layouts[8])
我不想将现有的幻灯片布局更改为slide_layouts style[8]
。
from pptx import Presentation
from pptx.util import Inches, Pt
from pptx.util import Inches
from pptx.enum.text import MSO_ANCHOR, MSO_AUTO_SIZE
prs = Presentation('test1.pptx')
slide = prs.slide_layouts(prs)
for shape in slide.placeholders:
print('%d %s' % (shape.placeholder_format.idx, shape.name))
答案 0 :(得分:1)
首先,您需要在幻灯片布局和幻灯片本身之间进行区别。您是否要获取有关布局或当前存在的幻灯片的信息?
对于当前现有的幻灯片,您可以从// Create some textfile in C:\Temp ..
string testFile = @"C:\Temp\test.txt";
using (File.Create(testFile))
{
}
// Choose the program to start. Path.Combine combines Paths, Directories and Filenames to one Path.
string path = Path.Combine(@"C:\Windows\System32", "notepad.exe");
// Your exe should have some arguments. In your case an IP-address i guess. If we start notepad we can tell him which file it should open.
string arguments = testFile;
// Start an exe with an argument
Process p = Process.Start(path, arguments);
// You would do the same if you push "Ctrl+R" and enter "C:\Windows\System32\Notepad.exe C:\Temp\test.txt"
// An now we tell our program to wait until the Process is closed..
p.WaitForExit();
对象访问幻灯片。要获得每张幻灯片的所有占位符,这将起作用:
slides
如果要(从母版中)获取布局的占位符,则需要访问for slide in prs.slides:
for shape in slide.placeholders:
print('%d %d %s' % (prs.slides.index(slide), shape.placeholder_format.idx, shape.name))
对象。
slide_layouts