_xdump.py 612 B

123456789101112131415
  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, 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. if v:
  14. vals.append(ref + "=" + v)
  15. print(rn, "|", " ; ".join(vals))