使用Python批量处理pptx文件,报错:KeyError:“There is no item named ‘ppt/slides/NULL“ in the archive

不知道为什么没有人提出过这个问题(可能没人遇到过吧。。)

搜了一下只有一篇StackOverflow的,大概讲一下:

问题主要出在使用pptx包Presentation() 打开pptx文件的时候

使用Python批量处理pptx文件,报错:KeyError:“There is no item named ‘ppt/slides/NULL“ in the archive_第1张图片

 后续使用 for slide in xxx.slides时,会找不到这个archive。。

这个主要的原因就是后续在读每个slide的时候,有个slide出问题了导致读不到,全部卡住(比较通俗不靠谱的说法)

看别人回复:

this is a bit of a thorny problem. The spec doesn't provide for a "broken" relationship (one that refers to a package-part that doesn't exist), but at least one library (Java-based if I recall correctly) does not clean up relationships properly in some cases, perhaps a slide delete operation in this case.

好回答,说了和没说一样。。

后续几个人提到的解决方法

1:File -> Info -> Check for Issues -> Inspect Document. 试了一下对我用处不大。

2:在Presentation() 和 for 中间加一个:slides = ppt.slides,试了,没用

3:简单粗暴,你ppt有问题我直接转存pdf再转回pptx...解决了

你可能感兴趣的:(powerpoint,python)