Пробовал этот блок кода. Как добавить фильтр в Excel при экспорте с использованием python. Пожалуйста, предложите мне способ решить эту проблему.
from openpyxl.worksheet.datavalidation import DataValidation
from openpyxl import load_workbook
def add_drop_down(file_path, file_name, row_total):
print("adding drop down")
wb = load_workbook("".join([file_path, file_name]))
ws = wb['Daily Report']
current_row = 2
while current_row < row_total + 2:
data_val_results = DataValidation(type="list",formula1="=='Daily Report'!C4:C100")
data_val_status = DataValidation(type="list",formula1="=='Daily Report'!D4:D100")
ws.add_data_validation(data_val_results)
ws.add_data_validation(data_val_status)
row_results = "".join(["C", str(current_row)])
row_status = "".join(["D", str(current_row)])
data_val_results.add(ws[row_results])
data_val_status.add(ws[row_status])
current_row += 1
wb.save("".join([file_path, file_name]))
dd = add_drop_down("C:/", 'Daily.xlsx', len(Piv2['Group']))