zoukankan      html  css  js  c++  java
  • 使用python获取pptx文件的文本内容范例

    get_text_from_pptx_pptm.py

    #!/bin/python
    # -*- coding: utf-8 -*-
    
    from pptx import Presentation
    import sys
    import base64
    
    reload(sys)
    sys.setdefaultencoding('utf8')
    
    fileName = sys.argv[1]
    # print(fileName)
    
    def tripSpace( str ):
        return str.replace(" ", "").replace(" ", "").replace("	", "").replace("
    ", "").replace("
    ", "").replace("
    ", "").replace("v", "")
    
    prs = Presentation(fileName)
    
    # ファイル概要(1スライド目のノート)
    file_summary = ""
    # ファイル注釈(2スライド目以降のノート)
    file_note = ""
    # ファイル内容(オブジェクトのテキスト全文)
    file_content = ""
    for i, sld in enumerate(prs.slides, start=1):
        for shp in sld.shapes:
            if shp.has_text_frame:
                file_content += shp.text
        if ( i == 1 ) :
            file_summary = sld.notes_slide.notes_text_frame.text
        else :
            file_note += tripSpace(sld.notes_slide.notes_text_frame.text)
        
    print(base64.b64encode(file_summary))
    print(tripSpace(file_note))
    print(tripSpace(file_content))
  • 相关阅读:
    索引
    互联网技术中的算法摘要
    Struts2(六)
    Struts2(五)
    Struts2(四)
    Struts2(三)
    Struts2(二)
    Struts2(一)
    WebService(三)
    WebService(二)
  • 原文地址:https://www.cnblogs.com/gaoBlog/p/14042502.html
Copyright © 2011-2022 走看看