# -*- coding: utf-8 -*- import os import sys try: from openpyxl import load_workbook except ImportError: import subprocess subprocess.check_call([sys.executable, "-m", "pip", "install", "openpyxl", "-q"]) from openpyxl import load_workbook out_path = r"c:\work\demo\dayang\mescloud\_extract_mes_progress_output.txt" out = open(out_path, "w", encoding="utf-8") def p(s=""): out.write(s + "\n") xlsx_path = r"c:\Users\j2742\Desktop\temp\大洋\实施文档\大洋-京宜安MES实施进度.xlsx" p("=" * 80) p("EXCEL FILE: " + xlsx_path) p("=" * 80) wb = load_workbook(xlsx_path, data_only=True) p("\n1. SHEET NAMES:") for i, name in enumerate(wb.sheetnames, 1): p(f" {i}. {name}") max_rows, max_cols = 150, 20 for sheet_name in wb.sheetnames: ws = wb[sheet_name] p("\n" + "=" * 80) p(f"SHEET: {sheet_name}") p(f"Dimensions (reported): {ws.dimensions}") p("=" * 80) count = 0 for row in ws.iter_rows(min_row=1, max_row=max_rows, min_col=1, max_col=max_cols): for cell in row: v = cell.value if v is not None and str(v).strip() != "": p(f" {cell.coordinate}: {v}") count += 1 p(f" --- Non-empty cells in range (1-{max_rows}, A-T): {count} ---") wb.close() def list_dir_depth(path, max_depth, current_depth=0, prefix=""): if not os.path.isdir(path): p(f" [NOT FOUND OR NOT A DIR]: {path}") return try: entries = sorted(os.listdir(path)) except Exception as e: p(f" [ERROR]: {path}: {e}") return for name in entries: full = os.path.join(path, name) if os.path.isdir(full): p(f"{prefix}[DIR] {name}/") if current_depth + 1 < max_depth: list_dir_depth(full, max_depth, current_depth + 1, prefix + " ") else: try: size = os.path.getsize(full) p(f"{prefix}[FILE] {name} ({size} bytes)") except Exception: p(f"{prefix}[FILE] {name}") p("\n" + "=" * 80) p(r"2. DIRECTORY: c:\Users\j2742\Desktop\temp\大洋\实施文档 (depth 2)") p("=" * 80) list_dir_depth(r"c:\Users\j2742\Desktop\temp\大洋\实施文档", 2) p("\n" + "=" * 80) p(r"3. DIRECTORY: c:\Users\j2742\Desktop\temp\大洋 (depth 2)") p("=" * 80) list_dir_depth(r"c:\Users\j2742\Desktop\temp\大洋", 2) out.close() print("Wrote", out_path)