Spaces:
Sleeping
Sleeping
File size: 2,009 Bytes
d2d455b 8491372 f7db5f7 d2d455b f7db5f7 d2d455b 8491372 d2d455b 8491372 f7db5f7 8491372 f7db5f7 f17e69e f7db5f7 f17e69e f7db5f7 8491372 12e8e5d d2d455b 8491372 d2d455b f7db5f7 d2d455b 857c739 f7db5f7 857c739 | 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 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | import gradio as gr
import openpyxl
from tempfile import NamedTemporaryFile
def process_excel(file):
wb = openpyxl.load_workbook(file, data_only=True)
# Create a new workbook for the result
result_wb = openpyxl.Workbook()
result_ws = result_wb.active
result_ws.title = "Official Visits"
# Header row
result_ws.append(["Employee ID (from G7)", "Sheet", "Row Data..."])
for sheet_name in wb.sheetnames:
ws = wb[sheet_name]
# Get employee ID from G7
emp_id = ws["G7"].value or "Unknown"
# Find the header row and locate 'Remarks' column
remarks_col_idx = None
header_row_idx = None
for row in ws.iter_rows(min_row=1, max_row=10):
headers = [str(cell.value).strip().lower() if cell.value else "" for cell in row]
if "remarks" in headers:
remarks_col_idx = headers.index("remarks")
header_row_idx = row[0].row
break
if remarks_col_idx is None:
continue # Skip this sheet if no 'Remarks' column found
for row in ws.iter_rows(min_row=header_row_idx + 1):
remarks_cell = row[remarks_col_idx]
if remarks_cell.value and "official visit" in str(remarks_cell.value).lower():
row_values = [cell.value for cell in row]
result_ws.append([emp_id, sheet_name] + row_values)
# Save to temporary file
with NamedTemporaryFile(delete=False, suffix=".xlsx") as tmp:
result_wb.save(tmp.name)
return tmp.name
# Gradio interface
iface = gr.Interface(
fn=process_excel,
inputs=gr.File(file_types=[".xlsx"]),
outputs=gr.File(label="Download Official Visit Report"),
title="Official Visit Extractor",
description="Upload an Excel file with multiple sheets. This tool finds rows where 'Remarks' contain 'Official visit' and compiles them. Employee ID is taken from cell G7 of each sheet."
)
if __name__ == "__main__":
iface.launch()
|