# -*- coding: utf-8 -*-
r"""B71: soi header + 3 dòng đầu của 4 file sạch T41 (để viết phép kiểm chứng đúng cột)."""
import os
import openpyxl

SACH = r'C:\Claw 2\Bao cao - Hanh chinh\Bao cao lam mau\da lam sach'
F = ['Tuan_41_05.10-11.10_DA-LAM-SACH.xlsx', 'Tuan_41_File1_Chinh_DA-LAM-SACH.xlsx',
     'Tuan_41_File2_KQM_DA-LAM-SACH.xlsx', 'Tuan_41_File3_W41_DA-LAM-SACH.xlsx']
for f in F:
    p = os.path.join(SACH, f)
    wb = openpyxl.load_workbook(p, read_only=True, data_only=True)
    for sn in wb.sheetnames:
        ws = wb[sn]
        rows = []
        for i, r in enumerate(ws.iter_rows(values_only=True)):
            if any(c not in (None, '') for c in r):
                rows.append(r)
            if len(rows) >= 4:
                break
        print('=== %s | sheet %s' % (f[:42], sn))
        for k, r in enumerate(rows):
            print('   dòng %d (%d cột): %s' % (k, len(r), [str(c)[:22] if c is not None else '' for c in r[:14]]))
        total = sum(1 for r in wb[sn].iter_rows(values_only=True) if any(c not in (None, '') for c in r))
        print('   tổng dòng có dữ liệu: %d' % total)
    wb.close()
    print()

p = os.path.join(SACH, 'Bao_cao_lam_sach_Tuan41.md')
print('=== BÁO CÁO MD DO AGY VIẾT (nguyên văn) ===')
print(open(p, encoding='utf-8', errors='replace').read())
