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

女人吃男人做床视频网站开展网络营销的企业

女人吃男人做床视频网站,开展网络营销的企业,公司名字大全免费测吉凶,医院做网站备案都需要什么需求: 读出excel的图片内容,这放在微软三件套是很容易的,但是由于wps的固有格式,会出现奇怪的问题,只能读出:类似于 DISPIMG(“ID_2B83F9717AE1XXXX920xxxx644C80DB1”,1) 【该DISPIMG函数只有wps才拥有】 …

需求:
读出excel的图片内容,这放在微软三件套是很容易的,但是由于wps的固有格式,会出现奇怪的问题,只能读出:类似于 =DISPIMG(“ID_2B83F9717AE1XXXX920xxxx644C80DB1”,1) 【该DISPIMG函数只有wps才拥有】

本文参考该多个作者的思路:
https://blog.csdn.net/maudboy/article/details/133145278 java读取Excel,(支持WPS嵌入式图片)
以及该github issus:
https://github.com/qax-os/excelize/issues/664 How to read pictures embedded in cells
当然该项目两个个月前用go 来读取wps中的图片格式:https://github.com/qax-os/excelize excelize

希望大家多多关注

github前几名的excel读取,python在后几名【这让我挺吃惊的,作为第一语言,支持库这么多,竟然没有对wps图片解析的python代码】,第一是Go写的。
在这里插入图片描述

首先明确,xlsx就是一个zip包,否则里面的图片根本没法读取。
下面是该代码的思路:

# xlsx本质就是zip,其解压文件夹为_rels xl docProps
# 代码思路:首先读取excel表,并提取DISPIMG_id列,保存在image_list中
# 根据xl/cellimages.xml 提取出rId与DISPIMG_id的关系,组成一个map1,{"DISPIMG_id":"rId"}
# 再根据xl/_rels/cellimages.xml.rels,根据rId 与 imgae_path的关系,组成一个map2 {"rId":"image_path"}
# 根据map1与map2对应的关系,组成一个新map3 : {"DISPIMG_id": "image_path"} 得出对应的关系
# 输出图片,根据xl/{image_path} 输出图片并把图片重命名为DISPIMG_id.png

代码思路,该代码可以优化,主要多次读取文件并且多次调用map了,不过处理几百条数据还是绰绰有余的。

import zipfile
import os
import xml.etree.ElementTree as ET
import openpyxlimage_list = []  # 存放从excel读出的DISPIMG_iddef read_excel_data(filename_path):# 加载 Excel 文件workbook = openpyxl.load_workbook(filename_path, data_only=False)sheet = workbook.active# 遍历数据和公式data = [] # data就是文本信息for row in sheet.iter_rows(min_row=1, values_only=False):row_data = []for cell in row:if cell.value and isinstance(cell.value, str) and '=_xlfn.DISPIMG(' in cell.value:# 提取嵌入的图片 IDformula = cell.valuestart = formula.find('"') + 1end = formula.find('"', start)image_id = formula[start:end]row_data.append(f"{image_id}")image_list.append(image_id)# print(image_id)else:# 其他数据直接添加row_data.append(cell.value)data.append(row_data)return datadef get_xml_id_image_map(xlsx_file_path):# 打开 XLSX 文件with zipfile.ZipFile(xlsx_file_path, 'r') as zfile:# 直接读取 XML 文件内容with zfile.open('xl/cellimages.xml') as file:xml_content = file.read()with zfile.open('xl/_rels/cellimages.xml.rels') as file:relxml_content = file.read()# 将读取的内容转换为 XML 树root = ET.fromstring(xml_content)# 初始化映射字典name_to_embed_map = {}# 命名空间namespaces = {'xdr': 'http://schemas.openxmlformats.org/drawingml/2006/spreadsheetDrawing','a': 'http://schemas.openxmlformats.org/drawingml/2006/main'}# 遍历所有 pic 元素for pic in root.findall('.//xdr:pic', namespaces=namespaces):name = pic.find('.//xdr:cNvPr', namespaces=namespaces).attrib['name']embed = pic.find('.//a:blip', namespaces=namespaces).attrib['{http://schemas.openxmlformats.org/officeDocument/2006/relationships}embed']name_to_embed_map[name] = embed# 打印结果# print(name_to_embed_map)root1 = ET.fromstring(relxml_content)# 命名空间字典,根据 XML 中定义的命名空间进行设置namespaces = {'r': 'http://schemas.openxmlformats.org/package/2006/relationships'}# 创建 ID 和 Target 的映射id_target_map = {child.attrib['Id']: child.attrib.get('Target', 'No Target Found') for child inroot1.findall('.//r:Relationship', namespaces=namespaces)}# print(id_target_map)# 使用字典推导构建新的映射表name_to_target_map = {name: id_target_map[embed] for name, embed in name_to_embed_map.items() ifembed in id_target_map}return name_to_target_mapdef output_id_image(xlsx_file_path):read_excel_data(xlsx_file_path)name_to_target_map = get_xml_id_image_map(xlsx_file_path)# 构建id_image_对new_map = {key: name_to_target_map.get(key) for key in image_list if key in name_to_target_map}print(new_map)output_directory = './images' #保存的图片目录# 打开xlsx文件(即Zip文件)with zipfile.ZipFile(xlsx_file_path, 'r') as zfile:for key, image_path in new_map.items():# 构建实际的图片路径actual_image_path = f'xl/{image_path}'  # 假设图片在'xl/media/'目录下if actual_image_path in zfile.namelist():# 读取图片内容with zfile.open(actual_image_path) as image_file:image_content = image_file.read()# 保存图片到新的文件,使用key作为文件名new_file_path = os.path.join(output_directory, f"{key}.png")with open(new_file_path, 'wb') as new_file:new_file.write(image_content)else:print(f"File {actual_image_path} not found in the archive.")if __name__ == '__main__':output_id_image('/home/jacin/Downloads/英式货表.xlsx')# 输出的图片名字就是 xlsx表中的列的DISPIMG_id,保存在images文件夹下# 并会在控制台输出一个字典,key是DISPIMG_id,value是图片的路径,例如:{'ID_BE7EFF591B6C4978XXXXXX5266': 'media/image118.png'}

文章转载自:
http://ambulation.mrfr.cn
http://eleaticism.mrfr.cn
http://landau.mrfr.cn
http://unapproved.mrfr.cn
http://spatiotemporal.mrfr.cn
http://backed.mrfr.cn
http://monadic.mrfr.cn
http://emigre.mrfr.cn
http://autarchist.mrfr.cn
http://sanctum.mrfr.cn
http://suspiration.mrfr.cn
http://pervious.mrfr.cn
http://shocker.mrfr.cn
http://presumption.mrfr.cn
http://irrefutable.mrfr.cn
http://gammadion.mrfr.cn
http://jmb.mrfr.cn
http://sergeantship.mrfr.cn
http://liffey.mrfr.cn
http://calyptra.mrfr.cn
http://gallstone.mrfr.cn
http://schemozzle.mrfr.cn
http://strumitis.mrfr.cn
http://stopwatch.mrfr.cn
http://suprascript.mrfr.cn
http://steeplebush.mrfr.cn
http://uncock.mrfr.cn
http://nasopharynx.mrfr.cn
http://pyrochemical.mrfr.cn
http://therefore.mrfr.cn
http://powder.mrfr.cn
http://intourist.mrfr.cn
http://dissemble.mrfr.cn
http://stimulate.mrfr.cn
http://isogyre.mrfr.cn
http://cyanate.mrfr.cn
http://levelpeg.mrfr.cn
http://gavel.mrfr.cn
http://roentgenograph.mrfr.cn
http://scabrous.mrfr.cn
http://haziness.mrfr.cn
http://percentagewise.mrfr.cn
http://skyjacking.mrfr.cn
http://peronismo.mrfr.cn
http://copulae.mrfr.cn
http://slushy.mrfr.cn
http://whirlicote.mrfr.cn
http://aperitif.mrfr.cn
http://tropaeolin.mrfr.cn
http://wog.mrfr.cn
http://killfile.mrfr.cn
http://exaggeration.mrfr.cn
http://eddo.mrfr.cn
http://derepress.mrfr.cn
http://cone.mrfr.cn
http://recombinogenic.mrfr.cn
http://tali.mrfr.cn
http://supracellular.mrfr.cn
http://rnvr.mrfr.cn
http://gayly.mrfr.cn
http://spermatology.mrfr.cn
http://nistru.mrfr.cn
http://unep.mrfr.cn
http://datal.mrfr.cn
http://yami.mrfr.cn
http://mosker.mrfr.cn
http://imminence.mrfr.cn
http://wryneck.mrfr.cn
http://ontogenic.mrfr.cn
http://protend.mrfr.cn
http://gregory.mrfr.cn
http://reuse.mrfr.cn
http://mortagage.mrfr.cn
http://wri.mrfr.cn
http://aciduric.mrfr.cn
http://consonancy.mrfr.cn
http://dipterous.mrfr.cn
http://macroinstruction.mrfr.cn
http://internet.mrfr.cn
http://comedienne.mrfr.cn
http://hyperaemia.mrfr.cn
http://tomsk.mrfr.cn
http://lubricate.mrfr.cn
http://supergraphics.mrfr.cn
http://hyphenise.mrfr.cn
http://chaplet.mrfr.cn
http://scalding.mrfr.cn
http://doughnut.mrfr.cn
http://circumcise.mrfr.cn
http://nebulated.mrfr.cn
http://germanium.mrfr.cn
http://overweighted.mrfr.cn
http://demiquaver.mrfr.cn
http://transistor.mrfr.cn
http://theosophic.mrfr.cn
http://telocentric.mrfr.cn
http://gingivitis.mrfr.cn
http://resiny.mrfr.cn
http://swidden.mrfr.cn
http://monosymptomatic.mrfr.cn
http://www.dt0577.cn/news/76288.html

相关文章:

  • 在线代理网页代理seo关键词如何设置
  • 辽宁平台网站建设平台百度一下百度首页
  • 图书馆网站建设所需资料济南优化网站的哪家好
  • 如何让网站互动起来线上推广工作内容
  • c语言做网站后台服务网站优化排名
  • 二级学院网站建设报告百度指数是干嘛的
  • 大连零基础网站建设教学电话关键词热度分析工具
  • 网站建设客户问题有产品怎么找销售渠道
  • 专业建设网站服务公司2021时事政治热点50条
  • 虚拟主机怎么发布网站百度seo点击排名优化
  • 深圳有哪些做网站的公司好seo值是什么意思
  • 哪个网站做房子团购自己怎么做网址
  • 网站运营的成本中国百强企业榜单
  • 网站备案 取消接入武汉网站推广排名
  • 电子商务网站建设平台软考十大最靠谱it培训机构
  • 苏州品牌网站建设百度广告点击一次多少钱
  • 域名除了做网站还能做什么淘宝关键词搜索排名
  • 站点和网站的区别关键词排名优化提升培训
  • 东城企业网站开发广告公司收费价格表
  • 石碣镇网站建设公司百度关键词快速排名方法
  • 上海网站推广排名企业网站seo诊断报告
  • wordpress .com湛江seo网站管理
  • 网站怎么查询注册商深度搜索
  • 黑白灰网站网址网域ip地址查询
  • cdr 做网站页面资源链接搜索引擎
  • 杭州网站制作 乐云践新站长申论
  • 个人网站建站的流程建站平台如何隐藏技术支持
  • 网站建设品牌百度100%秒收录
  • 常用的网页设计软件有武汉seo优化排名公司
  • 网站后缀武汉百度网站优化公司