pythonexcelopenpyxlstyleframe

excel file with the ability to filter columns


I need to create excel with columns that can be filited.

prefer to use openpyxl since I already use StyleFrame to style the excel.

example


Solution

  • Here is the solution using StyleFrame, I had to use the "row_to_add_filters" with index 0 to add filters to the columns....

    from StyleFrame import StyleFrame, colors
    
    excel_writer = StyleFrame.ExcelWriter('example.xlsx')
    sf = StyleFrame({'a': [1, 2, 3], 'b': [1, 1, 1], 'c': [2, 3, 4]})
    sf.apply_column_style(cols_to_style=['a', 'c'], protection=True, style_header=True)
    sf.apply_style_by_indexes(indexes_to_style=2, cols_to_style='b', bg_color=colors.yellow, protection=True)
    sf.to_excel(excel_writer=excel_writer, row_to_add_filters=0, columns_and_rows_to_freeze='B2', allow_protection=True)
    excel_writer.save()