使用openpyxl对Excel进行排序

时间:2017-06-08 07:10:08

标签: openpyxl

我的英语不好,对不起。 我正在尝试使用openpyxl和Python对表进行排序。我已经阅读了这些文件,我对此页面并不十分了解。我希望通过一些列对我的excel文件进​​行排序,排序依次为A列,然后是列B,然后是cloumn C,最后是列F.我的问题是如何使用add_sort_condition和add_filter_column这两种方式,只需简单方式会很棒。如果我能得到一个例子,那对我帮助很大!

wb_read = openpyxl.load_workbook(filename)
sheet_read = wb_read.get_active_sheet()
sheet_read.auto_filter.ref = 'A3:Q40000'
"""sheet_read.auto_filter.add_filter.column(2,['id'],blank=False) Didn't work
sheet_read.auto_filter.add_sort_condition('A') How and Where to use condition?
sheet_read.auto_filter.add_sort_condition('A3:Q40000') It seems didn't work again"""
wb_read.save('sorted.xlsx')

顺便说一句,如果我想排序,我是否必须使用auto_filter?

0 个答案:

没有答案