Refactor: Optimize error handling and support parsing of XLS(EXCEL97—2003) files. (#5633)

Optimize error handling and support parsing of XLS(EXCEL97—2003) files.
This commit is contained in:
hy89
2025-03-05 11:55:27 +08:00
committed by GitHub
parent 47684fa17c
commit b0c21b00d9
2 changed files with 27 additions and 71 deletions

View File

@ -20,7 +20,7 @@ from io import BytesIO
from xpinyin import Pinyin
import numpy as np
import pandas as pd
from openpyxl import load_workbook
# from openpyxl import load_workbook, Workbook
from dateutil.parser import parse as datetime_parse
from api.db.services.knowledgebase_service import KnowledgebaseService
@ -33,9 +33,9 @@ class Excel(ExcelParser):
def __call__(self, fnm, binary=None, from_page=0,
to_page=10000000000, callback=None):
if not binary:
wb = load_workbook(fnm)
wb = Excel._load_excel_to_workbook(fnm)
else:
wb = load_workbook(BytesIO(binary))
wb = Excel._load_excel_to_workbook(BytesIO(binary))
total = 0
for sheetname in wb.sheetnames:
total += len(list(wb[sheetname].rows))