# -*- coding: utf-8 -*-
r"""B169: đọc ĐẦY ĐỦ DOCX kết quả đo màu sau tái chế (Lộc 14/10) -> lưu text + in toàn bộ."""
import io
from docx import Document

P = r'C:\Claw 2\QC\_qc_loc1410\KIEM_TRA_MAU_SAU_TAI_CHE_TVT_WHITE_1410.docx'
RA = r'C:\Claw 2\QC\_qc_loc1410\DOCX_NOI_DUNG.txt'
d = Document(P)
ra = []
ra.append('=== ĐOẠN ===')
for x in d.paragraphs:
    t = x.text.rstrip()
    if t.strip():
        ra.append(t)
for i, b in enumerate(d.tables, 1):
    ra.append('=== BẢNG %d (%d dòng x %d cột) ===' % (i, len(b.rows), len(b.columns)))
    for r in b.rows:
        o = []
        for c in r.cells:
            o.append(' / '.join(p.text.strip() for p in c.paragraphs if p.text.strip()))
        ra.append(' || '.join(o))
io.open(RA, 'w', encoding='utf-8').write('\n'.join(ra))
print('  đã lưu:', RA, len('\n'.join(ra)), 'ký tự')
txt = '\n'.join(ra)
print('  --- MỤC C và D:')
i = txt.find('C. Kết quả')
print(txt[i:i + 400] if i > 0 else '(không thấy)')
print('  --- BẢNG 2 (đầy đủ từng ô):')
j = txt.find('=== BẢNG 2')
print(txt[j:j + 1200])
