fix: change export chart excel number type display type

This commit is contained in:
ulleo
2025-08-05 15:56:33 +08:00
parent aae7e39691
commit 3b081dee04
2 changed files with 6 additions and 6 deletions
+5 -6
View File
@@ -1,9 +1,6 @@
import asyncio
import datetime
import hashlib
import io
import traceback
import uuid
import numpy as np
import pandas as pd
@@ -14,9 +11,7 @@ from apps.chat.curd.chat import list_chats, get_chat_with_records, create_chat,
delete_chat, get_chat_chart_data, get_chat_predict_data
from apps.chat.models.chat_model import CreateChat, ChatRecord, RenameChat, ChatQuestion, ExcelData
from apps.chat.task.llm import LLMService
from common.core.config import settings
from common.core.deps import CurrentAssistant, SessionDep, CurrentUser
from starlette.responses import FileResponse
router = APIRouter(tags=["Data Q&A"], prefix="/chat")
@@ -209,8 +204,12 @@ async def export_excel(excel_data: ExcelData):
df = pd.DataFrame(np.array(data), columns=_fields_list)
buffer = io.BytesIO()
df.to_excel(buffer, index=False)
with pd.ExcelWriter(buffer, engine='xlsxwriter', engine_kwargs={'options': {'strings_to_numbers': True}}) as writer:
df.to_excel(writer, sheet_name='Sheet1', index=False)
buffer.seek(0)
return io.BytesIO(buffer.getvalue())
result = await asyncio.to_thread(inner)
return StreamingResponse(result, media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
+1
View File
@@ -40,6 +40,7 @@ dependencies = [
"fastapi-cache2>=0.2.2",
"sqlparse>=0.5.3",
"redis>=6.2.0",
"xlsxwriter>=3.2.5",
]
[[tool.uv.index]]
name = "default"