ragflow/python/parser/excel_parser.py
KevinHuSh 3245107dc7 use minio to store uploaded files; build dialog server; (#16)
* format code

* use minio to store uploaded files; build dialog server;
2023-12-25 19:05:59 +08:00

24 lines
645 B
Python

from openpyxl import load_workbook
import sys
from io import BytesIO
class HuExcelParser:
def __call__(self, fnm):
if isinstance(fnm, str):wb = load_workbook(fnm)
else: wb = load_workbook(BytesIO(fnm))
res = []
for sheetname in wb.sheetnames:
ws = wb[sheetname]
lines = []
for r in ws.rows:
lines.append(
"\t".join([str(c.value) if c.value is not None else "" for c in r]))
res.append(f"{sheetname}\n" + "\n".join(lines))
return res
if __name__ == "__main__":
psr = HuExcelParser()
psr(sys.argv[1])