鱼C论坛

 找回密码
 立即注册
查看: 22|回复: 1

PPT转word文档,不能识别分数形式的格式,怎么解决?

[复制链接]
发表于 7 小时前 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 Raddy 于 2026-1-15 08:32 编辑


  1. from pptx import Presentation
  2. from docx import Document
  3. from docx.shared import Pt, Inches, RGBColor
  4. from docx.oxml.shared import OxmlElement, qn
  5. import os
  6. import shutil
  7. import tempfile
  8. import re
  9. from PIL import Image  # 需要安装Pillow库来处理TIFF格式

  10. def clean_text(text):
  11.     """
  12.     清理文本,移除非XML兼容字符(控制字符、NULL字节等)
  13.     :param text: 输入文本
  14.     :return: 清理后的文本
  15.     """
  16.     # 保留可打印字符(包括中文、数字、标点等)
  17.     return ''.join(ch for ch in text if ch.isprintable())

  18. def extract_ppt_to_docx(pptx_path, output_path="output.docx"):
  19.     """
  20.     提取PPTX中的文字内容、公式和图片,输出为Word文档
  21.     :param pptx_path: PPTX文件路径
  22.     :param output_path: 输出Word文件路径
  23.     """
  24.     # 检查文件是否存在
  25.     if not os.path.exists(pptx_path):
  26.         print(f"❌ 错误:文件 {pptx_path} 不存在")
  27.         return

  28.     # 检查文件格式
  29.     if not pptx_path.lower().endswith('.pptx'):
  30.         print(f"❌ 错误:文件 {pptx_path} 不是PPTX格式")
  31.         return

  32.     try:
  33.         prs = Presentation(pptx_path)
  34.     except Exception as e:
  35.         print(f"❌ 错误:文件 {pptx_path} 无法打开(可能是PPT格式不对或损坏)")
  36.         print("提示:请确保是PPTX格式(Office 2007+),且文件路径正确")
  37.         return

  38.     # 创建临时目录用于存储图片
  39.     temp_dir = tempfile.mkdtemp()
  40.     print(f"📁 临时目录:{temp_dir}")
  41.    
  42.     doc = Document()
  43.     count_images = 0
  44.     count_formulas = 0
  45.    
  46.     # 遍历每张幻灯片
  47.     for slide_num, slide in enumerate(prs.slides, 1):
  48.         print(f"🔄 处理幻灯片 {slide_num}")
  49.         
  50.         # 提取标题
  51.         if slide.shapes.title:
  52.             title = slide.shapes.title.text.strip()
  53.             if title:
  54.                 title_para = doc.add_heading(title, level=1)
  55.                 title_para.runs[0].font.bold = True
  56.                 title_para.runs[0].font.color.rgb = RGBColor(0, 0, 128)
  57.         
  58.         # 处理所有形状
  59.         for shape_idx, shape in enumerate(slide.shapes):
  60.             print(f"   🔍 检查形状 {shape_idx}: 类型={shape.shape_type}, 是否有图片={hasattr(shape, 'image') and shape.image is not None}")
  61.             
  62.             # 1. 优先处理公式对象(不依赖关键词判断)
  63.             if shape.shape_type == 12:  # OLE Object (公式)
  64.                 print(f"   🧮 处理公式对象(不依赖关键词)")
  65.                 process_formula_object(shape, slide_num, temp_dir, doc, count_formulas)
  66.                 continue  # 跳过后续处理
  67.             
  68.             # 2. 处理图片(包含数学题的图片)
  69.             if shape.shape_type == 13 and hasattr(shape, 'image') and shape.image:
  70.                 print(f"   🖼️ 检查图片形状")
  71.                 if is_math_problem_image(slide):  # 仍然保留关键词判断
  72.                     process_image(shape, slide_num, shape_idx, temp_dir, doc, count_images)
  73.                     continue
  74.             
  75.             # 3. 处理普通文本(包含分数)
  76.             if shape.has_text_frame and shape.text_frame.text.strip():
  77.                 text = shape.text_frame.text.strip()
  78.                 if text:
  79.                     # 关键修复:清理文本防止XML错误
  80.                     cleaned_text = clean_text(text)
  81.                     # 处理分数格式
  82.                     processed_text = process_mixed_fraction(cleaned_text)
  83.                     
  84.                     # 添加段落
  85.                     p = doc.add_paragraph()
  86.                     p.paragraph_format.space_after = Pt(0)
  87.                     # 再次清理确保安全
  88.                     final_text = clean_text(processed_text)
  89.                     run = p.add_run(final_text)
  90.                     run.font.size = Pt(11)
  91.         
  92.         # 每张幻灯片后加个空行
  93.         if slide_num < len(prs.slides):
  94.             doc.add_paragraph()

  95.     # 保存Word文档
  96.     doc.save(output_path)
  97.     print(f"&#9989; 提取完成!已保存到 {output_path}(共 {len(prs.slides)} 张幻灯片,包含 {count_images} 张图片,{count_formulas} 个公式)")
  98.    
  99.     # 清理临时文件
  100.     try:
  101.         shutil.rmtree(temp_dir)
  102.         print(f"&#128465;&#65039; 临时目录已清理: {temp_dir}")
  103.     except Exception as e:
  104.         print(f"&#9888;&#65039; 清理临时目录失败: {e}")

  105. def process_formula_object(shape, slide_num, temp_dir, doc, count_formulas):
  106.     """处理公式对象(OLE Object),不依赖关键词判断"""
  107.     try:
  108.         # 尝试获取预览图片
  109.         if hasattr(shape, 'image') and shape.image and hasattr(shape.image, 'blob') and shape.image.blob:
  110.             # 保存预览图片
  111.             original_ext = 'png'
  112.             if hasattr(shape.image, 'filename') and shape.image.filename:
  113.                 original_ext = os.path.splitext(shape.image.filename)[1][1:].lower()
  114.             
  115.             formula_img_path = os.path.join(temp_dir, f"formula_{slide_num}_{shape.shape_id}.{original_ext}")
  116.             with open(formula_img_path, "wb") as f:
  117.                 f.write(shape.image.blob)
  118.             
  119.             # 处理TIFF格式
  120.             processed_img_path = formula_img_path
  121.             if original_ext.lower() in ['tiff', 'tif']:
  122.                 processed_img_path = convert_tiff_to_png(formula_img_path)
  123.                 if processed_img_path is None:
  124.                     print(f"   &#10060; 公式图片TIFF转换失败,跳过")
  125.                     return
  126.             
  127.             # 插入图片
  128.             if os.path.exists(processed_img_path) and os.path.getsize(processed_img_path) > 0:
  129.                 doc.add_paragraph().add_run().add_picture(processed_img_path, width=Inches(5))
  130.                 doc.add_paragraph()
  131.                 count_formulas += 1
  132.                 print(f"   &#9989; 公式图片已插入(计数: {count_formulas})")
  133.                 return
  134.         
  135.         # 2. 如果没有预览图片,尝试使用替代文本
  136.         alt_text = getattr(shape, 'text', None) or getattr(shape, 'alternative_text', '')
  137.         if alt_text:
  138.             # 关键修复:清理替代文本
  139.             cleaned_alt_text = clean_text(alt_text)
  140.             # 处理分数格式
  141.             processed_alt_text = process_mixed_fraction(cleaned_alt_text)
  142.             # 再次清理
  143.             final_alt_text = clean_text(processed_alt_text)
  144.             print(f"   &#128221; 处理公式替代文本: {final_alt_text}")
  145.             
  146.             p = doc.add_paragraph()
  147.             p.paragraph_format.space_after = Pt(0)
  148.             run = p.add_run(final_alt_text)
  149.             run.font.size = Pt(11)
  150.             run.font.italic = True
  151.             count_formulas += 1
  152.             print(f"   &#9989; 公式文本已插入(计数: {count_formulas})")
  153.             return
  154.    
  155.     except Exception as e:
  156.         print(f"   &#10060; 处理公式对象时出错: {e}")

  157. def process_image(shape, slide_num, shape_idx, temp_dir, doc, count_images):
  158.     """处理图片(包含数学题)"""
  159.     try:
  160.         # 保存图片
  161.         original_ext = 'png'
  162.         if hasattr(shape.image, 'filename') and shape.image.filename:
  163.             original_ext = os.path.splitext(shape.image.filename)[1][1:].lower()
  164.         
  165.         img_path = os.path.join(temp_dir, f"image_{slide_num}_{shape_idx}.{original_ext}")
  166.         with open(img_path, "wb") as f:
  167.             f.write(shape.image.blob)
  168.         
  169.         # 处理TIFF格式
  170.         processed_img_path = img_path
  171.         if original_ext.lower() in ['tiff', 'tif']:
  172.             processed_img_path = convert_tiff_to_png(img_path)
  173.             if processed_img_path is None:
  174.                 print(f"   &#10060; 图片TIFF转换失败,跳过")
  175.                 return
  176.         
  177.         # 插入图片
  178.         if os.path.exists(processed_img_path) and os.path.getsize(processed_img_path) > 0:
  179.             doc.add_paragraph().add_run().add_picture(processed_img_path, width=Inches(5))
  180.             doc.add_paragraph()
  181.             count_images += 1
  182.             print(f"   &#9989; 图片已插入(计数: {count_images})")
  183.     except Exception as e:
  184.         print(f"   &#10060; 保存或插入图片时出错: {e}")

  185. def process_mixed_fraction(text):
  186.     """
  187.     优化版分数处理:支持带分数和纯分数
  188.     示例:2 1/2 -> 2 1/2, 1/2 -> 1/2, -3/4 -> -3/4
  189.     """
  190.     # 1. 匹配带分数格式(整数+空格+分数)
  191.     # 2. 匹配纯分数格式(无整数部分)
  192.     pattern = r'(-?\d*)\s*(\d+)/(\d+)'
  193.    
  194.     # 用于替换的函数
  195.     def replace_func(match):
  196.         integer_part = match.group(1)
  197.         numerator = match.group(2)
  198.         denominator = match.group(3)
  199.         
  200.         # 处理整数部分为空的情况(纯分数)
  201.         if integer_part == '':
  202.             return f"{numerator}/{denominator}"
  203.         # 处理负号单独存在的情况(如-1/2)
  204.         elif integer_part == '-':
  205.             return f"-{numerator}/{denominator}"
  206.         else:
  207.             # 保留原始格式(带空格)
  208.             return f"{integer_part} {numerator}/{denominator}"
  209.    
  210.     # 执行替换
  211.     return re.sub(pattern, replace_func, text)

  212. def convert_tiff_to_png(tiff_path):
  213.     """将TIFF格式图片转换为PNG格式"""
  214.     try:
  215.         with Image.open(tiff_path) as img:
  216.             # 转换为RGB模式
  217.             if img.mode in ('RGBA', 'LA', 'P'):
  218.                 img = img.convert('RGB')
  219.             elif img.mode == 'CMYK':
  220.                 img = img.convert('RGB')
  221.             
  222.             # 生成PNG路径
  223.             png_path = tiff_path.replace('.tiff', '.png').replace('.tif', '.png')
  224.             
  225.             # 保存为PNG
  226.             img.save(png_path, 'PNG')
  227.             return png_path
  228.     except Exception as e:
  229.         print(f"   &#10060; TIFF转换失败: {e}")
  230.         return None

  231. def is_math_problem_image(slide):
  232.     """优化关键词检测(更全面)"""
  233.     slide_text = ""
  234.     for shape in slide.shapes:
  235.         if shape.has_text_frame and shape.text_frame.text.strip():
  236.             slide_text += shape.text_frame.text.strip() + " "
  237.    
  238.     # 更全面的关键词列表
  239.     math_keywords = [
  240.         '例题', '例', '题', '公式', '计算', '解', '证明', '几何', '代数', '方程',
  241.         '如图', '分数', '分子', '分母', '分式', '通分', '约分', '百分比', '小数', '根号'
  242.     ]
  243.    
  244.     # 检查关键词
  245.     for keyword in math_keywords:
  246.         if keyword in slide_text:
  247.             print(f"   &#128204; 检测到关键词 '{keyword}'")
  248.             return True
  249.    
  250.     # 检查分数格式(1/2, 2 1/2等)
  251.     if re.search(r'\d+/\d+', slide_text) or re.search(r'\d+\s+\d+/\d+', slide_text):
  252.         print(f"   &#128204; 检测到分数格式: {slide_text[:50]}...")
  253.         return True
  254.    
  255.     # 检查分数符号(&#189;, &#190;)
  256.     if re.search(r'[&#189;&#190;&#188;]', slide_text):
  257.         print(f"   &#128204; 检测到分数符号: {slide_text[:50]}...")
  258.         return True
  259.    
  260.     return False

  261. def batch_convert_pptx_to_docx(input_dir, output_dir=None):
  262.     """批量转换PPTX文件为DOCX"""
  263.     if not os.path.exists(input_dir):
  264.         print(f"&#10060; 错误:输入目录 {input_dir} 不存在")
  265.         return
  266.    
  267.     if output_dir is None:
  268.         output_dir = input_dir
  269.    
  270.     if not os.path.exists(output_dir):
  271.         os.makedirs(output_dir)
  272.    
  273.     # 获取所有PPTX文件
  274.     pptx_files = [f for f in os.listdir(input_dir) if f.lower().endswith('.pptx')]
  275.    
  276.     # 排除临时文件
  277.     pptx_files = [f for f in pptx_files if not f.startswith('~$')]
  278.    
  279.     if not pptx_files:
  280.         print(f"&#10060; 错误:在目录 {input_dir} 中没有找到PPTX文件")
  281.         return
  282.    
  283.     print(f"&#128269; 正在处理 {len(pptx_files)} 个PPTX文件...")
  284.    
  285.     for pptx_file in pptx_files:
  286.         input_path = os.path.join(input_dir, pptx_file)
  287.         output_file = os.path.splitext(pptx_file)[0] + ".docx"
  288.         output_path = os.path.join(output_dir, output_file)
  289.         
  290.         print(f"\n&#128196; 处理: {pptx_file}")
  291.         extract_ppt_to_docx(input_path, output_path)
  292.    
  293.     print(f"\n&#127881; 批量转换完成!共转换 {len(pptx_files)} 个文件")

  294. # ========== 使用示例 ==========
  295. if __name__ == "__main__":
  296.     # 设置输入目录(包含PPTX文件的目录)
  297.     input_dir = r"C:/Users/Administrator/Desktop/(高分突破·课件)25秋数学人教9全通用版/ppt/1.课堂导学案/第二十七章 相似"
  298.    
  299.     # 设置输出目录(默认与输入目录相同)
  300.     output_dir = r"C:/Users/Administrator/Desktop/(高分突破·课件)25秋数学人教9全通用版/word/27章"
  301.    
  302.     # 执行批量转换
  303.     batch_convert_pptx_to_docx(input_dir, output_dir)
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 7 小时前 | 显示全部楼层
您好!看到您PPT转Word代码在分数格式识别上遇到了问题。主要问题是PPT中的分数可能是特殊格式或图片,需要特别处理。

以下是对您代码的修改和优化,主要解决分数识别问题:

  • 1. 分数格式处理优化
  • 2. 特殊字符转换
  • 3. 改进的数学关键词检测


解决方案:


  1. import re
  2. from pptx import Presentation
  3. from docx import Document
  4. from docx.shared import Pt, Inches, RGBColor
  5. import os
  6. import shutil
  7. import tempfile
  8. from PIL import Image

  9. def clean_text(text):
  10.     """清理文本,移除非XML兼容字符"""
  11.     # 保留可打印字符(包括中文、数字、标点等)
  12.     return ''.join(ch for ch in text if ch.isprintable())

  13. def convert_fraction_symbols(text):
  14.     """转换HTML分数符号为普通分数格式"""
  15.     fraction_map = {
  16.         ' 1/2 ': '1/2',
  17.         ' 1/4 ': '1/4',
  18.         ' 3/4 ': '3/4',
  19.         ' 1/3 ': '1/3',
  20.         ' 2/3 ': '2/3',
  21.         ' 1/8 ': '1/8',
  22.         ' 3/8 ': '3/8',
  23.         ' 5/8 ': '5/8',
  24.         ' 7/8 ': '7/8',
  25.     }
  26.     for symbol, replacement in fraction_map.items():
  27.         text = text.replace(symbol, replacement)
  28.     return text

  29. def process_mixed_fraction(text):
  30.     """
  31.     优化版分数处理:支持带分数和纯分数
  32.     示例:2 1/2 -> 2 1/2, 1/2 -> 1/2, -3/4 -> -3/4
  33.     """
  34.     # 先转换分数符号
  35.     text = convert_fraction_symbols(text)
  36.    
  37.     # 1. 匹配带分数格式(整数+空格+分数)
  38.     # 2. 匹配纯分数格式(无整数部分)
  39.     pattern = r'(-?\d*)\s*(\d+)/(\d+)'
  40.    
  41.     # 用于替换的函数
  42.     def replace_func(match):
  43.         integer_part = match.group(1)
  44.         numerator = match.group(2)
  45.         denominator = match.group(3)
  46.         
  47.         # 处理整数部分为空的情况(纯分数)
  48.         if integer_part == '':
  49.             return f"{numerator}/{denominator}"
  50.         # 处理负号单独存在的情况(如-1/2)
  51.         elif integer_part == '-':
  52.             return f"-{numerator}/{denominator}"
  53.         else:
  54.             # 保留原始格式(带空格)
  55.             return f"{integer_part} {numerator}/{denominator}"
  56.    
  57.     # 执行替换
  58.     return re.sub(pattern, replace_func, text)

  59. def is_math_problem_image(slide):
  60.     """优化关键词检测(更全面)"""
  61.     slide_text = ""
  62.     for shape in slide.shapes:
  63.         if shape.has_text_frame and shape.text_frame.text.strip():
  64.             slide_text += shape.text_frame.text.strip() + " "
  65.    
  66.     # 更全面的关键词列表
  67.     math_keywords = [
  68.         '分数', '小数', '分子', '分母',
  69.         'ratio', 'fraction', 'decimal', 'numerator', 'denominator',
  70.         '计算', '算式', '解方程',
  71.         'math', 'calculate', 'equation',
  72.         '/', '÷', '×', '+', '-'
  73.     ]
  74.    
  75.     # 检查关键词
  76.     for keyword in math_keywords:
  77.         if keyword in slide_text:
  78.             return True
  79.    
  80.     # 检查分数格式(1/2, 2 1/2等)
  81.     if re.search(r'\d+/\d+', slide_text) or re.search(r'\d+\s+\d+/\d+', slide_text):
  82.         return True
  83.    
  84.     return False

  85. def extract_ppt_to_docx(pptx_path, output_path="output.docx"):
  86.     """
  87.     提取PPTX中的文字内容、公式和图片,输出为Word文档
  88.     """
  89.     if not os.path.exists(pptx_path):
  90.         print(f"错误:文件 {pptx_path} 不存在")
  91.         return

  92.     if not pptx_path.lower().endswith('.pptx'):
  93.         print(f"错误:文件 {pptx_path} 不是PPTX格式")
  94.         return

  95.     try:
  96.         prs = Presentation(pptx_path)
  97.     except Exception as e:
  98.         print(f"错误:文件 {pptx_path} 无法打开")
  99.         print("提示:请确保是PPTX格式(Office 2007+),且文件路径正确")
  100.         return

  101.     # 创建临时目录用于存储图片
  102.     temp_dir = tempfile.mkdtemp()
  103.     print(f"临时目录:{temp_dir}")
  104.    
  105.     doc = Document()
  106.     count_images = 0
  107.    
  108.     # 设置文档默认字体(可选)
  109.     style = doc.styles['Normal']
  110.     font = style.font
  111.     font.name = '宋体'
  112.     font.size = Pt(11)
  113.    
  114.     # 遍历每张幻灯片
  115.     for slide_num, slide in enumerate(prs.slides, 1):
  116.         print(f"处理幻灯片 {slide_num}")
  117.         
  118.         # 添加幻灯片标题
  119.         if slide.shapes.title:
  120.             title = slide.shapes.title.text.strip()
  121.             if title:
  122.                 title_para = doc.add_heading(title, level=1)
  123.                 title_para.runs[0].font.bold = True
  124.                 title_para.runs[0].font.color.rgb = RGBColor(0, 0, 128)
  125.         
  126.         # 处理所有形状
  127.         for shape_idx, shape in enumerate(slide.shapes):
  128.             # 1. 处理文本形状(包含分数)
  129.             if shape.has_text_frame and shape.text_frame.text.strip():
  130.                 text = shape.text_frame.text.strip()
  131.                 if text:
  132.                     # 清理文本防止XML错误
  133.                     cleaned_text = clean_text(text)
  134.                     # 处理分数格式
  135.                     processed_text = process_mixed_fraction(cleaned_text)
  136.                     
  137.                     # 添加段落
  138.                     p = doc.add_paragraph()
  139.                     p.paragraph_format.space_after = Pt(6)
  140.                     run = p.add_run(processed_text)
  141.                     run.font.size = Pt(11)
  142.             
  143.             # 2. 处理图片(包含数学题图片)
  144.             elif shape.shape_type == 13 and hasattr(shape, 'image') and shape.image:
  145.                 # 检查是否是数学相关图片
  146.                 if is_math_problem_image(slide):
  147.                     try:
  148.                         # 保存图片
  149.                         img_path = os.path.join(temp_dir, f"image_{slide_num}_{shape_idx}.png")
  150.                         with open(img_path, "wb") as f:
  151.                             f.write(shape.image.blob)
  152.                         
  153.                         # 插入图片
  154.                         if os.path.exists(img_path) and os.path.getsize(img_path) > 0:
  155.                             doc.add_paragraph().add_run().add_picture(img_path, width=Inches(4))
  156.                             count_images += 1
  157.                     except Exception as e:
  158.                         print(f"保存或插入图片时出错: {e}")
  159.         
  160.         # 每张幻灯片后加分隔线
  161.         if slide_num < len(prs.slides):
  162.             doc.add_paragraph("--- 下一页 ---").alignment = 1

  163.     # 保存Word文档
  164.     doc.save(output_path)
  165.     print(f"提取完成!已保存到 {output_path}")
  166.     print(f"共 {len(prs.slides)} 张幻灯片,包含 {count_images} 张图片")
  167.    
  168.     # 清理临时文件
  169.     try:
  170.         shutil.rmtree(temp_dir)
  171.         print(f"临时目录已清理: {temp_dir}")
  172.     except Exception as e:
  173.         print(f"清理临时目录失败: {e}")

  174. def batch_convert_pptx_to_docx(input_dir, output_dir=None):
  175.     """批量转换PPTX文件为DOCX"""
  176.     if not os.path.exists(input_dir):
  177.         print(f"错误:输入目录 {input_dir} 不存在")
  178.         return
  179.    
  180.     if output_dir is None:
  181.         output_dir = input_dir
  182.    
  183.     if not os.path.exists(output_dir):
  184.         os.makedirs(output_dir)
  185.    
  186.     # 获取所有PPTX文件
  187.     pptx_files = [f for f in os.listdir(input_dir) if f.lower().endswith('.pptx')]
  188.    
  189.     if not pptx_files:
  190.         print(f"错误:在目录 {input_dir} 中没有找到PPTX文件")
  191.         return
  192.    
  193.     print(f"正在处理 {len(pptx_files)} 个PPTX文件...")
  194.    
  195.     for pptx_file in pptx_files:
  196.         input_path = os.path.join(input_dir, pptx_file)
  197.         output_file = os.path.splitext(pptx_file)[0] + ".docx"
  198.         output_path = os.path.join(output_dir, output_file)
  199.         
  200.         print(f"\n处理: {pptx_file}")
  201.         extract_ppt_to_docx(input_path, output_path)
  202.    
  203.     print(f"\n批量转换完成!共转换 {len(pptx_files)} 个文件")

  204. # ========== 使用示例 ==========
  205. if __name__ == "__main__":
  206.     # 单个文件转换示例
  207.     # extract_ppt_to_docx("input.pptx", "output.docx")
  208.    
  209.     # 批量转换示例
  210.     input_dir = r"C:/Users/Administrator/Desktop/课件文件夹"
  211.     output_dir = r"C:/Users/Administrator/Desktop/输出文件夹"
  212.    
  213.     # 执行批量转换
  214.     batch_convert_pptx_to_docx(input_dir, output_dir)
复制代码


主要改进:

  • 分数符号转换:添加了 convert_fraction_symbols() 函数,将HTML分数符号(如 1/2 、 1/4 )转换为普通分数格式(1/2、1/4)
  • 更智能的分数检测:改进的 process_mixed_fraction() 函数能识别带分数和纯分数
  • 简化的图片处理:直接保存图片为PNG格式,避免TIFF转换问题
  • 更好的数学关键词检测:添加了更多中英文数学关键词
  • 代码完整性:补全了缺失的变量定义


使用建议:

  • 安装必要的库:pip install python-pptx python-docx Pillow
  • 如果PPT中的分数是图片形式,代码会自动检测数学关键词并插入图片
  • 如果分数是文本形式,代码会尝试转换为标准分数格式


如果仍有分数无法识别,可能是以下原因:
1. 分数是特殊字体或符号
2. 分数是复杂的数学公式对象
3. 分数被嵌入到其他形状中

您可以根据实际情况调整数学关键词列表或添加特定的分数检测规则。

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
小甲鱼最新课程 -> https://ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2026-1-15 16:10

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表