#!/usr/bin/env python3 """Print sheet names and the first N rows of each sheet of an .xlsx (exploration helper). Usage: python3 -I xlsx_peek.py [rows_per_sheet] [sheet_name] """ import os import sys sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) from xlsxlite import Workbook # noqa: E402 def main() -> None: path = sys.argv[1] n = int(sys.argv[2]) if len(sys.argv) > 2 else 5 only = sys.argv[3] if len(sys.argv) > 3 else None wb = Workbook(path) for name in wb.sheets: if only and name != only: continue print("=== sheet:", repr(name)) count = 0 for i, row in enumerate(wb.rows(name)): if i < n: print(i, [str(x)[:60] if x is not None else None for x in row]) count += 1 print("rows:", count) if __name__ == "__main__": main()