从xlsx 文件中获取图片位置
import base64
import re
import xml.dom.minidom as xmldom
import os
import zipfile
import shutil
import xlrd
def isfile_exist(file_path):
if not os.path.isfile(file_path):
print("It's not a file or no such file exist ! %s" % file_path)
return False
else:
return True
# 复制并修改指定目录下的文件类型名,将excel后缀名修改为.zip
def copy_change_file_name(file_path, new_type='.zip'):
if not isfile_exist(file_path):
return ''
extend = os.path.splitext(file_path)[1] # 获取文件拓展名
if extend != '.xlsx' and extend != '.xls':
print("It's not a excel file! %s" % file_path)
return False
file_name = os.path.basename(file_path) # 获取文件名
new_name = str(file_name.split('.')[0]) + new_type # 新的文件名,命名为:xxx.zip
dir_path = os.path.dirname(file_path) # 获取文件所在目录
new_path = os.path.join(dir_path, new_name) # 新的文件路径
if os.path.exists(new_path):
os.remove(new_path)
shutil.copyfile(file_path, new_path)
return new_path # 返回新的文件路径,压缩包
# 解压文件
def unzip_file(zipfile_path):
if not isfile_exist(zipfile_path):
return False
if os.path.splitext(zipfile_path)[1] != '.zip':
print("It's not a zip file! %s" % zipfile_path)
return False
file_zip = zipfile.ZipFile(zipfile_path, 'r')
file_name