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

织梦网站tag怎么做wordpress ip黑名单

织梦网站tag怎么做,wordpress ip黑名单,云南移动和生活app安装,女生做网站开发需求#xff1a; 读出excel的图片内容#xff0c;这放在微软三件套是很容易的#xff0c;但是由于wps的固有格式#xff0c;会出现奇怪的问题#xff0c;只能读出#xff1a;类似于 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_onlyFalse)sheet workbook.active# 遍历数据和公式data [] # data就是文本信息for row in sheet.iter_rows(min_row1, values_onlyFalse):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, namespacesnamespaces):name pic.find(.//xdr:cNvPr, namespacesnamespaces).attrib[name]embed pic.find(.//a:blip, namespacesnamespaces).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, namespacesnamespaces)}# 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 fxl/{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(fFile {actual_image_path} not found in the archive.)if __name__ __main__:output_id_image(/home/jacin/Downloads/英式货表.xlsx)# 输出的图片名字就是 xlsx表中的列的DISPIMG_id保存在images文件夹下# 并会在控制台输出一个字典key是DISPIMG_idvalue是图片的路径,例如{ID_BE7EFF591B6C4978XXXXXX5266: media/image118.png}
http://www.hkea.cn/news/14478086/

相关文章:

  • 门户网站开发投标文件企业网站优化策略
  • 怎样拍照产品做网站百度认证官方网站
  • 网站搜索优化方案18岁以上站长统计
  • 全国各地网站开发外包h5动画制作
  • 建设一个行业性的网站价格网站二级栏目如何调用
  • 河北省建设厅网站农安县建设局网站
  • 云虚拟主机做视频网站wordpress精美免费主题
  • 如何创建一个企业网站建设美食网站的威胁
  • 小型旅游网站汕头建设银行
  • 自己的网站怎么做下载链接网站页面设计要求
  • 老板合作网站开发电商销售渠道有哪些
  • 做网站公奇闻司郑州汉狮阳江问政平台官网入口
  • 网站建设与制作报价深圳网站制作济南
  • 化隆县公司网站建设网站费用多少钱一年
  • 意外险平台服务网站centos7删除wordpress
  • 相册特效手机网站seo一个月工资一般多少
  • 保定网站制作排名需要多少钱分销系统app
  • 网站建设合同封皮祥网站建设
  • 海南省海口市建设厅网站高权重网站做员会来顶排名
  • 南充市住房和城乡建设局网站沧州网站制作的流程
  • 网站名百度搜不到seo专家招聘
  • 宁波建网站方式做网站做哪个
  • 营销型网站建设公司哪家好哪个好微信公众平台网站建设
  • 河南高端网站建设公司wordpress主题php破解
  • 网站建设方案可行性权威行业网站建设公司
  • 寮步营销型网站建设怎么可以自己制作网站
  • 哪些网站可以做直播个人网页设计html代码免费
  • 服务平台名称大全网络seo培训
  • 网站没有经过我司审核通过白名单上海网站制作软件
  • 永康哪有做网站的公司杭州建设主管部门的网站