openpyxl-数据排序,过滤器

过滤器,数据排序

from openpyxl import Workbook

wb = Workbook()
sheet = wb.active

data = [
['Item', 'Colour'],
['pen', 'brown'],
['book', 'black'],
['plate', 'white'],
['chair', 'brown'],
['coin', 'gold'],
['bed', 'brown'],
['notebook', 'white'],
]

for r in data:
sheet.append(r)

sheet.auto_filter.ref = 'A1:B8'
sheet.auto_filter.add_filter_column(1, ['brown', 'white'])
sheet.auto_filter.add_sort_condition('B2:B8')

wb.save('C:/Users/Administrator/Desktop/filtered.xlsx')


实现效果如下:

 

 

posted @ 2023-07-24 17:22  往事已成昨天  阅读(270)  评论(0编辑  收藏  举报