_xdump2.py 734 B

12345678910111213141516
  1. # -*- coding: utf-8 -*-
  2. # 临时脚本:导出xlsx逐格+合并区诊断
  3. import zipfile, re, sys
  4. z = zipfile.ZipFile(sys.argv[1])
  5. s = z.read("xl/worksheets/sheet1.xml").decode("utf-8")
  6. rows = re.findall(r'<row r="(\d+)"[^>]*>(.*?)</row>', s, re.S)
  7. for rn, body in rows:
  8. cells = re.findall(r'<c r="([A-Z]+\d+)"([^/>]*)(?:/>|>(.*?)</c>)', body, re.S)
  9. vals = []
  10. for ref, attr, inner in cells:
  11. m = re.findall(r'<t[^>]*>([^<]*)</t>|<v>([^<]*)</v>', inner)
  12. v = " ".join(a or b for a, b in m)
  13. st = re.search(r's="(\d+)"', attr)
  14. vals.append(ref + ("[s" + st.group(1) + "]" if st else "") + "=" + v)
  15. print(rn, "|", " ; ".join(vals))
  16. print("MERGES:", re.findall(r'<mergeCell ref="([^"]+)"', s))