MCPcopy Index your code
hub / github.com/dataease/SQLBot / parse_excel

Function parse_excel

backend/apps/datasource/api/datasource.py:537–555  ·  view source on GitHub ↗
(file: UploadFile = File(..., description=f"{PLACEHOLDER_PREFIX}ds_excel"))

Source from the content-addressed store, hash-verified

535@router.post("/parseExcel", response_model=None, summary=f"{PLACEHOLDER_PREFIX}ds_parse_excel")
536@require_permissions(permission=SqlbotPermission(role=['ws_admin']))
537async def parse_excel(file: UploadFile = File(..., description=f"{PLACEHOLDER_PREFIX}ds_excel")):
538 ALLOWED_EXTENSIONS = {".xlsx", ".xls", ".csv"}
539 if not file.filename.lower().endswith(tuple(ALLOWED_EXTENSIONS)):
540 raise HTTPException(400, "Only support .xlsx/.xls/.csv")
541
542 os.makedirs(path, exist_ok=True)
543 filename = f"{file.filename.split('.')[0].split('/')[-1]}_{hashlib.sha256(uuid.uuid4().bytes).hexdigest()[:10]}.{file.filename.split('.')[-1]}"
544 save_path = os.path.join(path, filename)
545 with open(save_path, "wb") as f:
546 f.write(await file.read())
547
548 def inner():
549 sheets_data = parse_excel_preview(save_path)
550 return {
551 "filePath": filename,
552 "data": sheets_data
553 }
554
555 return await asyncio.to_thread(inner)
556
557
558@router.post("/importToDb", response_model=None, summary=f"{PLACEHOLDER_PREFIX}ds_import_to_db")

Callers

nothing calls this directly

Calls 2

openFunction · 0.85
readMethod · 0.80

Tested by

no test coverage detected