1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| import os import pandas as pd import datetime
path = r'D:\softwares\FineReport_10.0\webapps\webroot\WEB-INF\reportlets' findstring = 'sp_product' liststring = []
for root, dirs, files in os.walk(path): for name in files: if name.endswith('.cpt'): filepath = open(os.path.join(root, name), 'r', encoding='utf-8') if findstring in filepath.read(): filename = filepath.name.replace(path, '').replace('\\','/') liststring.append(filename[1:])
if len(liststring)==0: print("未找到此字段!") else : today= datetime.date.today() df = pd.DataFrame(liststring,columns=['报表名称']) excelname = r"D:\files\帆软报表中存在"+findstring+"数据的文件名称-"+today.strftime('%Y-%m-%d')+".xlsx" df.to_excel(excelname,index=False) print("输出到excel成功!")
|