Skip to content

Commit 5e0d804

Browse files
authored
fix: Excel export prohibits inputting external links or formulas (#3105)
1 parent 8903b35 commit 5e0d804

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

apps/dataset/serializers/document_serializers.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
from django.db.models import QuerySet, Count
2424
from django.db.models.functions import Substr, Reverse
2525
from django.http import HttpResponse
26+
from django.utils.translation import get_language
27+
from django.utils.translation import gettext_lazy as _, gettext, to_locale
2628
from drf_yasg import openapi
2729
from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE
2830
from rest_framework import serializers
@@ -64,8 +66,6 @@
6466
embedding_by_document_list
6567
from setting.models import Model
6668
from smartdoc.conf import PROJECT_DIR
67-
from django.utils.translation import gettext_lazy as _, gettext, to_locale
68-
from django.utils.translation import get_language
6969

7070
parse_qa_handle_list = [XlsParseQAHandle(), CsvParseQAHandle(), XlsxParseQAHandle(), ZipParseQAHandle()]
7171
parse_table_handle_list = [CsvSplitTableHandle(), XlsSplitTableHandle(), XlsxSplitTableHandle()]
@@ -661,7 +661,10 @@ def get_workbook(data_dict, document_dict):
661661
cell = worksheet.cell(row=row_idx + 1, column=col_idx + 1)
662662
if isinstance(col, str):
663663
col = re.sub(ILLEGAL_CHARACTERS_RE, '', col)
664-
cell.value = col
664+
if col.startswith(('=', '+', '-', '@')):
665+
cell.value = '\ufeff' + col
666+
else:
667+
cell.value = col
665668
# 创建HttpResponse对象返回Excel文件
666669
return workbook
667670

0 commit comments

Comments
 (0)