diff --git a/apps/common/drf/renders/excel.py b/apps/common/drf/renders/excel.py index 0d1cb8d51..e4cd9f0ce 100644 --- a/apps/common/drf/renders/excel.py +++ b/apps/common/drf/renders/excel.py @@ -1,5 +1,6 @@ from openpyxl import Workbook from openpyxl.writer.excel import save_virtual_workbook +from openpyxl.cell.cell import ILLEGAL_CHARACTERS_RE from .base import BaseFileRenderer @@ -20,7 +21,9 @@ class ExcelFileRenderer(BaseFileRenderer): self.row_count += 1 column_count = 0 for cell_value in row: + # 处理非法字符 column_count += 1 + cell_value = ILLEGAL_CHARACTERS_RE.sub(r'', cell_value) self.ws.cell(row=self.row_count, column=column_count, value=cell_value) def get_rendered_value(self):