fix: improve error message when uploading Excel file with incorrect column count

This commit is contained in:
ulleo
2025-11-27 14:56:51 +08:00
committed by ulleo
parent d916e2911f
commit 8023ce2907
9 changed files with 62 additions and 6 deletions
@@ -17,6 +17,7 @@ from apps.data_training.models.data_training_model import DataTrainingInfo
from common.core.config import settings
from common.core.deps import SessionDep, CurrentUser, Trans
from common.utils.data_format import DataFormat
from common.utils.excel import get_excel_column_count
router = APIRouter(tags=["DataTraining"], prefix="/system/data-training")
@@ -136,6 +137,9 @@ async def upload_excel(trans: Trans, current_user: CurrentUser, file: UploadFile
for sheet_name in sheet_names:
if get_excel_column_count(save_path, sheet_name) < len(use_cols):
raise Exception(trans("i18n_excel_import.col_num_not_match"))
df = pd.read_excel(
save_path,
sheet_name=sheet_name,
@@ -17,6 +17,7 @@ from apps.terminology.models.terminology_model import TerminologyInfo
from common.core.config import settings
from common.core.deps import SessionDep, CurrentUser, Trans
from common.utils.data_format import DataFormat
from common.utils.excel import get_excel_column_count
router = APIRouter(tags=["Terminology"], prefix="/system/terminology")
@@ -133,6 +134,9 @@ async def upload_excel(trans: Trans, current_user: CurrentUser, file: UploadFile
for sheet_name in sheet_names:
if get_excel_column_count(save_path, sheet_name) < len(use_cols):
raise Exception(trans("i18n_excel_import.col_num_not_match"))
df = pd.read_excel(
save_path,
sheet_name=sheet_name,