You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
955 B
33 lines
955 B
"""
|
|
pip install python-pptx
|
|
"""
|
|
from pptx import Presentation
|
|
import os
|
|
|
|
|
|
def extract_text_from_pptx(file_path):
|
|
"""从pptx文件中提取所有文本内容"""
|
|
prs = Presentation(file_path)
|
|
text_content = []
|
|
|
|
# 遍历所有幻灯片
|
|
for slide in prs.slides:
|
|
# 遍历幻灯片中的所有形状
|
|
for shape in slide.shapes:
|
|
if hasattr(shape, "text"):
|
|
text = shape.text.strip()
|
|
if text: # 只添加非空文本
|
|
text_content.append(text)
|
|
|
|
return '\n'.join(text_content)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
# 示例用法
|
|
pptx_file = "../Txt/东师理想智慧教学管理应用介绍.pptx" # 替换为实际文件路径
|
|
if os.path.exists(pptx_file):
|
|
text = extract_text_from_pptx(pptx_file)
|
|
print("提取的文本内容:")
|
|
print(text)
|
|
else:
|
|
print(f"文件 {pptx_file} 不存在") |