您好,登錄后才能下訂單哦!
1.雙擊執(zhí)行程序,并輸入要檢查的目錄(包含子目錄下所有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"為要查詢的擴(kuò)展名
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()
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。