def write_form_description_as_cell_comment( worksheet: Worksheet, form_names: List[str], question_index_to_row_index: Dict[int, int], form_name_to_description: Dict[str, str], ) -> None: # add form description as comment to column and make every other form # appear in different color last_form_name = "" i = 1 for form_name in form_names: if form_name != last_form_name: last_form_name = form_name if form_name in form_name_to_description: worksheet.write_comment( question_index_to_row_index[i + 1], 0, form_name_to_description[form_name], ) i = i + 1
def add_cell_validation( worksheet: Worksheet, row_index: int, column_index: int, full_question_path: Tuple[str, ...], question: Dict[str, Any], question_to_cell: Dict[Tuple[str, ...], str], bool_options: Dict[str, str], date_format: Format, black_format: Format, ) -> None: type = question["questionType"] has_options = "options" in question if type == "BOOL": worksheet.data_validation( row_index, column_index, row_index, column_index, { "validate": "list", "source": list(bool_options.values()) }, ) elif has_options: options = question["options"] if "multiOptions" in question and question["multiOptions"]: s = set(options) multi_options = sum( map(lambda r: sorted(list(combinations(s, r))), range(1, len(s) + 1)), [], ) options = [ ";".join(multi_option) for multi_option in multi_options ] worksheet.data_validation( row_index, column_index, row_index, column_index, { "validate": "list", "source": options }, ) elif type == "INTEGER": worksheet.data_validation( row_index, column_index, row_index, column_index, { "validate": "integer", "criteria": ">", "value": -(2**32) }, ) elif type == "FLOAT": worksheet.data_validation( row_index, column_index, row_index, column_index, { "validate": "decimal", "criteria": ">", "value": -(2**32) }, ) elif type == "DATE": worksheet.write_datetime( row_index, column_index, datetime.strptime("01/01/1970", "%d/%m/%Y"), date_format, ) if "questionDescription" in question: worksheet.write_comment(row_index, column_index, question["questionDescription"]) if "dependsOn" in question: write_conditional_blank_color_if_dependency_fails( worksheet, row_index, column_index, question, full_question_path, question_to_cell, bool_options, black_format, )