Este script escanea varias hojas de mi reporte contando cuantas veces aparece la palabra "documents" en una columna. Cada vez que se ejecuta el programa, registra los resultados en un archivo de texto:
import time, re
from win32com import client
#the log file
f = open('C:/Users/Ruben Torres/Desktop/Scripts/KPIs/filinglog.txt', 'a')
#open report
xl = client.Dispatch("Excel.Application")
report = xl.workbooks.open('D:/RubenBK/REPORTS/cctableruben.xlsm')
#file records counters
guayaquilCount = 0
quitoCount = 0
expressCount = 0
sparesCount = 0
lastrow = report.sheets("Guayaquil").usedrange.Rows.Count
for cel in report.sheets("Guayaquil").Range("N8", "N" + str(lastrow)):
if re.search(r'^[dD]\w+[sS]', str(cel.value)):
guayaquilCount += 1
lastrow = report.sheets("Quito").usedrange.Rows.Count
for cel in report.sheets("Quito").Range("N8", "N" + str(lastrow)):
if re.search(r'^[dD]\w+[sS]', str(cel.value)):
quitoCount += 1
lastrow = report.sheets("Express").usedrange.Rows.Count
for cel in report.sheets("Express").Range("K8", "K" + str(lastrow)):
if re.search(r'^[dD]\w+[sS]', str(cel.value)):
expressCount += 1
lastrow = report.sheets("Spare Parts").usedrange.Rows.Count
for cel in report.sheets("Spare Parts").Range("N8", "N" + str(lastrow)):
if re.search(r'^[dD]\w+[sS]', str(cel.value)):
sparesCount += 1
t = time.localtime()
f.write("\nFecha: %s-%s-%s" %(t.tm_year, t.tm_mon, t.tm_mday) + " Archivado en Guayaquil: %i; Quito: %i; Express: %i; Spares: %i " %(guayaquilCount, quitoCount, expressCount, sparesCount))
f.close
f = open('C:/Users/Ruben Torres/Desktop/Scripts/KPIs/filinglog.txt')
for l in f.readlines():
print l
f.close
raw_input()
No hay comentarios:
Publicar un comentario