计算指定目录下所有我的
以下是我的尝试:
此外,我尝试使用python-pptx,但是我遇到了lxml错误(因此尝试构建自己的lxml;但由于iconv依赖问题而出现错误)。另外,由于它只支持pptx,我需要找到另一种针对ppt的替代方法。PowerPoint 2013 x64已安装,并且我正在使用Python 2.7.4 x64。
如何使用Python从PowerPoint演示文稿中获取幻灯片总数?
.docx
、.doc
、.ppt
、.pptx
和 .pdf
文件的总页数;但是我有点困惑如何计算幻灯片的页数。以下是我的尝试:
from glob import glob
from PyPDF2 import PdfFileReader
import win32com.client
def pdf_page_count(filename):
curr = open(filename, "rb")
page_count = PdfFileReader(curr).getNumPages()
curr.close()
return page_count
def presentation_slide_count(filename):
Application = win32com.client.Dispatch("PowerPoint.Application")
Presentation = Application.Presentations.Open(filename)
slide_count = len(Presentation.Slides)
Presentation.Close()
return slide_count
if __name__=='__main__':
powerpoints = glob('*/*/*.pptx') + glob('*/*/*.ppt')
documents = glob('*/*/*.docx') + glob('*/*/*.doc')
pdf = glob('*/*/*.pdf')
total_pdf_pages = sum([pdf_page_count(pdf) for pdf in pdf])
total_docx_pages = 0
total_powerpoint_slides = sum([presentation_slide_count(presentation)
for presentation in powerpoints])
print total_pdf_pages
print total_powerpoint_slides
此外,我尝试使用python-pptx,但是我遇到了lxml错误(因此尝试构建自己的lxml;但由于iconv依赖问题而出现错误)。另外,由于它只支持pptx,我需要找到另一种针对ppt的替代方法。PowerPoint 2013 x64已安装,并且我正在使用Python 2.7.4 x64。
如何使用Python从PowerPoint演示文稿中获取幻灯片总数?
Presentation = Application.Presentations.Open(curr)
,但是出现了以下错误:File "<COMObject <unknown>>", line 3, in Open pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, None, None, 0, -2147024773), None)
。 - A T