55 lines
1.5 KiB
Python
55 lines
1.5 KiB
Python
"""Диагностика шаблона формы."""
|
|
import zipfile
|
|
from xml.etree import ElementTree as ET
|
|
|
|
tmpl = "data/Исх.данные/1. 74 34 0400007 ГК вымпел-73/ШАБЛОН.xlsx"
|
|
with zipfile.ZipFile(tmpl) as z:
|
|
xml = z.read("xl/worksheets/sheet1.xml").decode("utf-8")
|
|
ss_xml = z.read("xl/sharedStrings.xml").decode("utf-8") if "xl/sharedStrings.xml" in z.namelist() else "<sst/>"
|
|
|
|
# Sharedstrings
|
|
ss_root = ET.fromstring(ss_xml)
|
|
ns0 = "http://schemas.openxmlformats.org/spreadsheetml/2006/main"
|
|
strings = []
|
|
for si in ss_root:
|
|
texts = []
|
|
for t in si.iter(f"{{{ns0}}}t"):
|
|
texts.append(t.text or "")
|
|
strings.append("".join(texts))
|
|
|
|
# Merged cells
|
|
root = ET.fromstring(xml)
|
|
ns = {"s": ns0}
|
|
mc = root.find(".//s:mergeCells", ns)
|
|
if mc is not None:
|
|
print("=== MERGED CELLS ===")
|
|
for m in mc:
|
|
print(" ", m.get("ref"))
|
|
print()
|
|
|
|
# Row heights
|
|
print("=== ROW HEIGHTS ===")
|
|
for rd in root.findall(".//s:row", ns):
|
|
r = rd.get("r")
|
|
ht = rd.get("ht")
|
|
if ht and float(ht) > 15:
|
|
print(f" Row {r}: height={ht}")
|
|
|
|
print()
|
|
print("=== ALL NON-EMPTY CELLS ===")
|
|
for row_el in root.findall(".//s:row", ns):
|
|
for c in row_el.findall("s:c", ns):
|
|
ref = c.get("r", "")
|
|
t = c.get("t", "")
|
|
v = c.find("s:v", ns)
|
|
if v is None:
|
|
continue
|
|
val = v.text or ""
|
|
if t == "s":
|
|
try:
|
|
val = strings[int(val)]
|
|
except Exception:
|
|
pass
|
|
if val.strip():
|
|
print(f" {ref}: {repr(val[:80])}")
|