您好,登錄后才能下訂單哦!
1.雙擊執行程序,并輸入要檢查的目錄(包含子目錄下所有xlsx,xls)
2.如有檢查到excel中有插圖,程序輸出文件seekfile_result.txt,并顯示插圖所在文件 sheet表及圖所在位置。
import os
import win32com.client
import xlrd
def run_fast_scandir(dir, key1, key2): # dir: str, ext: list 搜索文件
subfolders, files = [], []
for f in os.scandir(dir):
if f.is_dir():
subfolders.append(f.path)
if f.is_file():
if key1.lower() in f.name.lower() or key2.lower() in f.name.lower():
files.append(f.path)
for dir in list(subfolders):
sf, f = run_fast_scandir(dir, key1, key2)
subfolders.extend(sf)
files.extend(f)
return subfolders, files
def get_xls_sheets(xlsfile): # 獲取文件中的sheet表名
xls = xlrd.open_workbook(xlsfile, on_demand=True)
return xls.sheet_names()
def check_pic(xlsfile, sheet): #檢查Sheet中是否有圖
x = win32com.client.Dispatch("Excel.Application")
wb = x.Workbooks.Open(xlsfile)
ws = wb.Sheets(sheet)
for k in ws.Shapes:
result_file.writelines(xlsfile + " "+sheet+" ")
result_file.writelines(k.TopLeftCell.Address + "\n")
wb = x.WorkBooks.Close()
if name == "main":
seek_path = input("Input search path (like: d:\test):")
subfolders,files = run_fast_scandir(seek_path, "xlsx", "xls") #"xlsx","xls"為要查詢的擴展名
i = -1
result_file = open("seekfile_result.txt", "a+")
for f in files:
i += 1
xls_sheets = get_xls_sheets(files[i])
for xls_sheet in xls_sheets:
check_pic(files[i], xls_sheet)
result_file.close()
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。