首页 > 其他分享 >ExtractOfficeContent: 提取Office文件中文本、表格和图像

ExtractOfficeContent: 提取Office文件中文本、表格和图像

时间:2023-06-10 16:25:26浏览次数:45  
标签:Office 表格 img ppt path ExtractOfficeContent SAVE extract dir

引言

  • 最近有空写了一下这个库,用来提取Office文件中的文本和图像内容,用作后续整理训练语料使用。
  • 最新更新请移步:Github

Extract Office Content

PyPI

Use

  1. Installextract_office_content
    $ pip install extract_office_content
    
  2. Run by CLI.
    • Extract All office file's content.
      $ extract_office_content -h
      usage: extract_office_content [-h] [-img_dir SAVE_IMG_DIR] file_path
      
      positional arguments:
      file_path
      
      optional arguments:
      -h, --help            show this help message and exit
      -img_dir SAVE_IMG_DIR, --save_img_dir SAVE_IMG_DIR
      
      $ extract_office_content tests/test_files
      
    • Extract Word.
      $ extract_word -h
      usage: extract_word [-h] [-img_dir SAVE_IMG_DIR] word_path
      
      positional arguments:
      word_path
      
      optional arguments:
      -h, --help            show this help message and exit
      -img_dir SAVE_IMG_DIR, --save_img_dir SAVE_IMG_DIR
      
      $ extract_word tests/test_files/word_example.docx
      
    • Extract PPT.
      $ extract_ppt -h
      usage: extract_ppt [-h] [-img_dir SAVE_IMG_DIR] ppt_path
      
      positional arguments:
      ppt_path
      
      optional arguments:
      -h, --help            show this help message and exit
      -img_dir SAVE_IMG_DIR, --save_img_dir SAVE_IMG_DIR
      
      $ extract_ppt tests/test_files/ppt_example.pptx
      
    • Extract Excel.
      $ extract_excel -h
      usage: extract_excel [-h] [-f {markdown,html,latex,string}] [-o SAVE_IMG_DIR]
                          excel_path
      
      positional arguments:
      excel_path
      
      optional arguments:
      -h, --help            show this help message and exit
      -f {markdown,html,latex,string}, --output_format {markdown,html,latex,string}
      -o SAVE_IMG_DIR, --save_img_dir SAVE_IMG_DIR
      
      $ extract_excel tests/test_files/excel_example.xlsx
      
  3. Run by python script.
    • Extract all.
      from pathlib import Path
      
      from extract_office_content import ExtractOfficeContent
      
      
      extracter = ExtractOfficeContent()
      
      
      file_list = list(Path('tests/test_files').iterdir())
      
      for file_path in file_list:
          res = extracter(file_path)
          print(res)
      
    • Extract Word.
      from extract_office_content import ExtractWord
      
      
      word_extract = ExtractWord()
      
      word_path = 'tests/test_files/word_example.docx'
      text = word_extract(word_path, "outputs/word")
      print(text)
      
    • Extract PPT.
      from pathlib import Path
      
      from extract_office_content import ExtractPPT
      
      ppt_extracter = ExtractPPT()
      
      ppt_path = 'tests/test_files/ppt_example.pptx'
      save_dir = 'outputs'
      save_img_dir = Path(save_dir) / Path(ppt_path).stem
      res = ppt_extracter(ppt_path, save_img_dir=str(save_img_dir))
      print(res)
      
    • Extract Excel.
      from extract_office_content import ExtractExcel
      
      excel_extract = ExtractExcel()
      
      excel_path = 'tests/test_files/excel_with_image.xlsx'
      res  = excel_extract(excel_path, out_format='markdown', save_img_dir='1')
      print(res)
      

参考资料

标签:Office,表格,img,ppt,path,ExtractOfficeContent,SAVE,extract,dir
From: https://www.cnblogs.com/shiwanghualuo/p/17471441.html

相关文章

  • Python实现Excel与Word文件中表格数据的导入导出
    问题描述:Excel文件“测试文件.xlsx”中有3个worksheet,每个worksheet中的行数和列数都不相同,要求把这3个worksheet中的数据导入到一个Word文件中,每个worksheet生成一个单独的表格,每个表格的样式不同。在Excel和Word之间,是支持表格直接复制的,如果数量少,可以直接复制,如果多的话,可以参......
  • Python使用tkinter的Treeview组件实现表格功能
    fromtkinterimportTk,Scrollbar,Framefromtkinter.ttkimportTreeview#创建tkinter应用程序窗口root=Tk()#设置窗口大小和位置root.geometry('500x300+400+300')#不允许改变窗口大小root.resizable(False,False)#设置窗口标题root.title('通信录管理系统')#使......
  • graalvm nodejs + spire office 实现office 处理
    实际上是一个比较简单的处理,主要是利用了graalvm的nodejs可以方便的使用外部jar,我们就可以使用其他nodejsweb框架,结合spireoffice实现专业可靠的office转换处理预备主要是安装graalvm以及nodejsgraalvm已经不支持包含nodejs了,需要独立安装参考对于grralvm安装......
  • 【前端】elementUI表格根据状态显示不同的字体颜色
    elementUI表格根据状态显示不同的字体颜色elementUI官网:https://element.eleme.cn/#/zh-CNcell-style:单元格的style的回调方法,也可以使用一个固定的Object为所有单元格设置一样的Style。实现效果:实现步骤:el-table标签中增加一个方法回调,:cell-style=“cellStyle”。在方法中......
  • 【前端方案】-表格排序列LRU缓存方案(二)
    一.目标个人账号的设置记忆功能-避免用户每次登录之后重新对表单字段做展示设置二、存储方案轻量方案结合localstorage低容量存储(5M),根据LRU只存最近访问的20至30张表格列配置数据全量方案大内存G级别,使用indexedDb进行存储,有多少表格操作列数据就存多少,结合第三方库dexie.......
  • 转载:PageOffice动态生成Word文件并转换为PDF
    说明:PageOffice是客户端插件,做不到纯后台调用把word转为pdf。但是pageoffice的FileMaker对象可以实现不在客户端打开文件直接转换文件为pdf并保存到服务器端,看起来跟服务器端转换的效果一样。1、环境前端:vue后端:springboot、pageoffice5.4.0.3版本2、前端在index.vue页面定......
  • ChatGPT玩法(二):AI玩转Excel表格处理
    前言在线免费体验ChatGpt:https://www.topgpt.one你是否还在为记不住Excel的繁琐函数和公式而苦恼?如果是这样,那么不妨试试ChatExcel。即使你对函数一窍不通,也能轻松处理表格。只要你能清楚地描述你的需求,它就可以帮你搞定。此外,ChatExcel的作者还制作了一张工作流程对比图,一眼就......
  • React学习时,自己拟定的一则小案例(table表格组件,含编辑)
    某次在Uniapp群看到有人问uniapp如何操作dom元素。他想对这张表标红的区域,做dom元素获取,因为产品想让红色色块点击时,成为可编辑,渲染1~4月份之间的行程安排。于是,有小伙伴说让他用position定位这里,点击时使红色色块层级抬高,弄个input上去。但提问的小伙伴并没有决定这么做,随后......
  • python操作Excel,读取表格内容,并根据需求将内容填充到表格指定位置
    在日常工作中经常会遇到需要将“表一,部门信息表”内容逐行填充到“表二,个人基本信息表”的情况。表一:表二:  实现方式如下:#!usr/bin/python#-*-coding:utf-8-*-importpandasaspdimportopenpyxlasopfromopenpyxlimportWorkbookfromopenpyxlimportl......
  • OpenOffice4.1.6 linux安装/卸载教程
    以下是centos的安装方法1.先安装并配置好jdk2.拷贝把Apache_OpenOffice_4.1.6_Linux_x86-64_install-rpm_zh-CN.tar.gz拷贝到自己想要文件路径,例:/home/temp3.解压tarzxvfApache_OpenOffice_4.1.6_Linux_x86-64_install-rpm_zh-CN.tar.gz解压后会有一个zh-CN文件夹4.安......