41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
"""Dump .xls (BIFF) content: sheets, merged cells, all non-empty cell values."""
|
|
import sys
|
|
import xlrd
|
|
|
|
def dump(path):
|
|
print("=" * 100)
|
|
print("FILE:", path)
|
|
try:
|
|
bk = xlrd.open_workbook(path, formatting_info=True)
|
|
fi = True
|
|
except Exception as e:
|
|
print(" [formatting_info unavailable: %s]" % e)
|
|
bk = xlrd.open_workbook(path)
|
|
fi = False
|
|
print("sheets:", bk.sheet_names(), " nsheets:", bk.nsheets)
|
|
for sh in bk.sheets():
|
|
print("-" * 100)
|
|
print("SHEET: %s (%d rows x %d cols)" % (sh.name, sh.nrows, sh.ncols))
|
|
if fi:
|
|
try:
|
|
merged = sh.merged_cells
|
|
if merged:
|
|
print("MERGED:", merged)
|
|
except Exception:
|
|
pass
|
|
for r in range(sh.nrows):
|
|
row_vals = []
|
|
for c in range(sh.ncols):
|
|
v = sh.cell_value(r, c)
|
|
if isinstance(v, float) and v == int(v):
|
|
v = int(v)
|
|
s = str(v).strip()
|
|
if s:
|
|
row_vals.append("%s%d=%s" % (chr(65 + c) if c < 26 else "c" + str(c), r + 1, s))
|
|
if row_vals:
|
|
print(" | ".join(row_vals))
|
|
|
|
for p in sys.argv[1:]:
|
|
dump(p)
|