Sanitize worksheet titles
This commit is contained in:
parent
548d3c3c75
commit
e4c9a3ef44
|
|
@ -185,7 +185,7 @@ def export_feedback(course_session_ids: list[str], save_as_file: bool):
|
|||
|
||||
|
||||
def _create_sheet(wb: Workbook, title: str, data: list[FeedbackResponse]):
|
||||
sheet = wb.create_sheet(title=title)
|
||||
sheet = wb.create_sheet(title=_sanitize_sheet_name(title))
|
||||
|
||||
if len(data) == 0:
|
||||
return sheet
|
||||
|
|
@ -208,6 +208,24 @@ def _create_sheet(wb: Workbook, title: str, data: list[FeedbackResponse]):
|
|||
return sheet
|
||||
|
||||
|
||||
def _sanitize_sheet_name(text, default_name="DefaultSheet"):
|
||||
if text is None:
|
||||
return default_name
|
||||
|
||||
prohibited_chars = ["\\", "/", "*", "?", ":", "[", "]"]
|
||||
for char in prohibited_chars:
|
||||
text = text.replace(char, "")
|
||||
|
||||
text = text.strip("'")
|
||||
|
||||
text = text[:31]
|
||||
|
||||
if len(text) == 0:
|
||||
return default_name
|
||||
|
||||
return text
|
||||
|
||||
|
||||
def _add_rows(sheet, data, question_data):
|
||||
for row_idx, feedback in enumerate(data, start=2):
|
||||
sheet.cell(row=row_idx, column=1, value=feedback.course_session.title)
|
||||
|
|
|
|||
Loading…
Reference in New Issue