From 1c35f2216f63111e92c6c3a3ec044f9b146f854d Mon Sep 17 00:00:00 2001 From: Sumit Bhanushali Date: Mon, 5 Aug 2024 18:01:30 +0530 Subject: [PATCH] fix(XLSX): remove unsupported characters from sheet title --- frappe/utils/xlsxutils.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/frappe/utils/xlsxutils.py b/frappe/utils/xlsxutils.py index 9442a4c367..53b44bd5ca 100644 --- a/frappe/utils/xlsxutils.py +++ b/frappe/utils/xlsxutils.py @@ -8,6 +8,7 @@ import xlrd from openpyxl import load_workbook from openpyxl.styles import Font from openpyxl.utils import get_column_letter +from openpyxl.workbook.child import INVALID_TITLE_REGEX import frappe from frappe.utils.html_utils import unescape_html @@ -21,7 +22,8 @@ def make_xlsx(data, sheet_name, wb=None, column_widths=None): if wb is None: wb = openpyxl.Workbook(write_only=True) - ws = wb.create_sheet(sheet_name, 0) + sheet_name_sanitized = INVALID_TITLE_REGEX.sub(" ", sheet_name) + ws = wb.create_sheet(sheet_name_sanitized, 0) for i, column_width in enumerate(column_widths): if column_width: