Skip to content

Commit 3b081de

Browse files
committed
fix: change export chart excel number type display type
1 parent aae7e39 commit 3b081de

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

backend/apps/chat/api/chat.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
import asyncio
2-
import datetime
3-
import hashlib
42
import io
53
import traceback
6-
import uuid
74

85
import numpy as np
96
import pandas as pd
@@ -14,9 +11,7 @@
1411
delete_chat, get_chat_chart_data, get_chat_predict_data
1512
from apps.chat.models.chat_model import CreateChat, ChatRecord, RenameChat, ChatQuestion, ExcelData
1613
from apps.chat.task.llm import LLMService
17-
from common.core.config import settings
1814
from common.core.deps import CurrentAssistant, SessionDep, CurrentUser
19-
from starlette.responses import FileResponse
2015

2116
router = APIRouter(tags=["Data Q&A"], prefix="/chat")
2217

@@ -209,8 +204,12 @@ def inner():
209204
df = pd.DataFrame(np.array(data), columns=_fields_list)
210205

211206
buffer = io.BytesIO()
212-
df.to_excel(buffer, index=False)
207+
208+
with pd.ExcelWriter(buffer, engine='xlsxwriter', engine_kwargs={'options': {'strings_to_numbers': True}}) as writer:
209+
df.to_excel(writer, sheet_name='Sheet1', index=False)
210+
213211
buffer.seek(0)
214212
return io.BytesIO(buffer.getvalue())
213+
215214
result = await asyncio.to_thread(inner)
216215
return StreamingResponse(result, media_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")

backend/pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ dependencies = [
4040
"fastapi-cache2>=0.2.2",
4141
"sqlparse>=0.5.3",
4242
"redis>=6.2.0",
43+
"xlsxwriter>=3.2.5",
4344
]
4445
[[tool.uv.index]]
4546
name = "default"

0 commit comments

Comments
 (0)