我正在尝试通过使用python-pptx库获取pptx文件中文本框内文字的字体大小。但是,我的代码在运行时不断输出"Default size"。
以下是代码:
from pptx import Presentation
pptx_file = 'education.pptx'
presentation = Presentation(pptx_file)
for slide_index, slide in enumerate(presentation.slides):
# 遍历当前幻灯片中的每一个形状
for shape in slide.shapes:
if shape.has_text_frame:
# 遍历文本框中的每一段落
for paragraph in shape.text_frame.paragraphs:
# 遍历段落中的每一处文本
for run in paragraph.runs:
font_size = run.font.size
# 字体大小以Pt为单位,如果有必要可以转换为更易读的格式
font_size_pt = font_size.pt if font_size else 'Default size'
print(f"幻灯片{slide_index + 1},文本:{run.text},字体大小:{font_size_pt}")
我已经尽力去获取文本框中字体的大小了,并且查阅了相关文档,但未能找到解决此问题的有效答案。希望有人能提供帮助。