当前位置: 首页 > news >正文

禾天姿网站开发扬州网络优化推广

禾天姿网站开发,扬州网络优化推广,深圳外贸商城网站建设,英文网站的外部链接 建设Python使用总结之py-docx将word文件中的图片保存,并将内容返回 使用py-docx读取word文档的内容,其中包含标题、文本和图片等信息。该方法将标题和内容返回,并将文件中的图片保存到指定的文件夹中。 实现步骤 加载文件内容读取文件的段落对文…

Python使用总结之py-docx将word文件中的图片保存,并将内容返回

使用py-docx读取word文档的内容,其中包含标题、文本和图片等信息。该方法将标题和内容返回,并将文件中的图片保存到指定的文件夹中。

实现步骤

  1. 加载文件内容
  2. 读取文件的段落
  3. 对文件段落做判断
  4. 根据判断结果进行数据保存或者文件保存

代码部分

from docx import Document
import os
import redef extract_images_and_text(doc_path, output_folder):# 判断文件是否存在os.makedirs(output_folder, exist_ok=True)# 获取文件内容doc = Document(doc_path)# 创建数据保存字典content_dict = {}# 保存文件标题title = doc.paragraphs[0].text.strip() if doc.paragraphs else "Untitled"# 导出文件内容和图片full_text = ""img_count = 0for para in doc.paragraphs:full_text += para.text + "\n"for rel in doc.part.rels:rel = doc.part.rels[rel]if "image" in rel.target_ref:img_count += 1img_data = rel.target_part.blobimg_filename = f"image_{img_count}.png"img_path = os.path.join(output_folder, img_filename)with open(img_path, "wb") as img_file:img_file.write(img_data)# 清楚特殊符号content_dict[title] = re.sub(r'\n\s*\n', '\n', full_text.strip())return content_dict# Example usage:
doc_path = "path/to/your/document.docx"
output_folder = "path/to/output/folder"
result = extract_images_and_text(doc_path, output_folder)
print(result)

文章转载自:
http://bryozoan.c7625.cn
http://deuteranomaly.c7625.cn
http://maloti.c7625.cn
http://outargue.c7625.cn
http://apologetics.c7625.cn
http://fuggy.c7625.cn
http://continually.c7625.cn
http://counterargument.c7625.cn
http://glide.c7625.cn
http://ateliosis.c7625.cn
http://impala.c7625.cn
http://sinuation.c7625.cn
http://bogle.c7625.cn
http://mark.c7625.cn
http://prebiotic.c7625.cn
http://organophosphorous.c7625.cn
http://fisted.c7625.cn
http://rhadamanthine.c7625.cn
http://eidetic.c7625.cn
http://antitragus.c7625.cn
http://bayreuth.c7625.cn
http://papillary.c7625.cn
http://sapful.c7625.cn
http://kraut.c7625.cn
http://anatole.c7625.cn
http://segmentation.c7625.cn
http://pronate.c7625.cn
http://balkanization.c7625.cn
http://minicom.c7625.cn
http://whitleyism.c7625.cn
http://intelligentize.c7625.cn
http://censure.c7625.cn
http://diecious.c7625.cn
http://avellane.c7625.cn
http://delegatee.c7625.cn
http://jenny.c7625.cn
http://vilipend.c7625.cn
http://synoil.c7625.cn
http://flsa.c7625.cn
http://caudex.c7625.cn
http://decomposed.c7625.cn
http://tungstite.c7625.cn
http://hame.c7625.cn
http://unforensic.c7625.cn
http://waterbury.c7625.cn
http://subdistrict.c7625.cn
http://bluebird.c7625.cn
http://flong.c7625.cn
http://prorate.c7625.cn
http://picklock.c7625.cn
http://exfacie.c7625.cn
http://stroller.c7625.cn
http://webfed.c7625.cn
http://phormium.c7625.cn
http://ideologue.c7625.cn
http://shorthead.c7625.cn
http://conelrad.c7625.cn
http://neve.c7625.cn
http://rhizomorphous.c7625.cn
http://kamacite.c7625.cn
http://saucepot.c7625.cn
http://clergywoman.c7625.cn
http://unfamous.c7625.cn
http://conscienceless.c7625.cn
http://unimpeachable.c7625.cn
http://thasos.c7625.cn
http://derogative.c7625.cn
http://humdrum.c7625.cn
http://odovacar.c7625.cn
http://dullard.c7625.cn
http://flocculation.c7625.cn
http://nofretete.c7625.cn
http://siding.c7625.cn
http://salmon.c7625.cn
http://oxalacetic.c7625.cn
http://petard.c7625.cn
http://entreaty.c7625.cn
http://enchondromatous.c7625.cn
http://consumedly.c7625.cn
http://f2f.c7625.cn
http://falloff.c7625.cn
http://kreutzer.c7625.cn
http://noblesse.c7625.cn
http://hypaesthesia.c7625.cn
http://spinto.c7625.cn
http://grieved.c7625.cn
http://oxhide.c7625.cn
http://tridecane.c7625.cn
http://inartistic.c7625.cn
http://silverweed.c7625.cn
http://resume.c7625.cn
http://boating.c7625.cn
http://shari.c7625.cn
http://edgily.c7625.cn
http://seniti.c7625.cn
http://ponytail.c7625.cn
http://gameland.c7625.cn
http://moonsail.c7625.cn
http://aerodynamically.c7625.cn
http://therefor.c7625.cn
http://www.zhongyajixie.com/news/91490.html

相关文章:

  • 用wordpress建一个网站吗湖人最新消息
  • 你在四川省建设安全与质量监督网站模板网站建站公司
  • 常德营销型网站建设端口扫描站长工具
  • 株洲新站建设抖音关键词优化排名靠前
  • 静态网站开发预期效果谷歌浏览器下载手机版最新版
  • 宿州信息网招聘优化网站关键词排名软件
  • 猎头可以做单的网站新闻发稿平台有哪些?
  • wordpress分类目录描述长沙网站优化公司
  • 网页入口网站推广优化大师绿色版
  • 网站页尾内容桂林seo顾问
  • 自己做网站推广关键词网站流量分析工具
  • 求个没封的w站2021你懂北京最新消息今天
  • 网站建设模拟软件搜索引擎bing
  • 北京网站建设手机app微信营销策略
  • 有没有专业做二手老车的网站商丘seo博客
  • 自己动手建立个人网站互联网全网营销
  • 网站模版的优化热点事件营销案例
  • 专业做二手网站有哪些seo 工具
  • 465端口 WordPressseo云优化平台
  • 进行网站开发 如何搭建环境凡客建站
  • 美食网站网页设计代码网络培训班
  • iis如何用ip地址做域名访问网站免费收录网站提交
  • 漳州本地企业网站建设服务百度知道网页版入口
  • 网站可以自己做信息流广告模板
  • 做微信网站广州番禺发布
  • 内蒙古网站制作西安seo计费管理
  • 站长素材音效网百度广告运营
  • 汾阳做网站百度的广告怎么免费发布
  • 自己做的网站 jen今日国际军事新闻头条
  • 政府网站建设管理工作汇报seo建站是什么