Openpyxl Filter and Sort Data

Filter Data

  • The auto_filter attribute is employed to line filtering and sorting conditions.
 Openpyxl Filter

Openpyxl Filter

Sample Code

from openpyxl import Workbook  
wb = Workbook()  
sheet =

sheet['A3'] = 40  
sheet['B3'] = 26  

row_count = [  

for row in row_count:  


for a1,a2 in sheet[sheet.dimensions]:  
print(a1.value, a2.value)  

sheet.auto_filter.add_filter_column(1, ['40', '26'])'dimension_1.xlsx')  


Merge Data

  • We can merge the cell using the merge_cells() method. once we merge the cells, the top-left one is removed from the worksheet
  • The openpyxl also provides the unmerged_cells() method to unmerge the cell.
 Openpyxl Merger

Openpyxl Merge

Sample Code

from openpyxl.styles import Alignment  

wb = Workbook()  
sheet =


cell = sheet.cell(row=1, column=1)  
cell.value = 'Wikitechy'  
cell.alignment = Alignment(horizontal='center', vertical='center')'merging.xlsx')  


Openpyxl Merge Output

Related Searches to Openpyxl Filter and Sort Data

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add to your ad blocking whitelist or disable your adblocking software.