/usr/lib/python2.7/dist-packages/openpyxl/worksheet/filters.py is in python-openpyxl 2.3.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | from __future__ import absolute_import
# Copyright (c) 2010-2015 openpyxl
def normalize_reference(cell_range):
# Normalize range to a str or None
if not cell_range:
cell_range = None
elif isinstance(cell_range, str):
cell_range = cell_range.upper()
else: # Assume a row generator
cell_range = tuple(cell_range)
first_cell = cell_range[0][0]
last_cell = cell_range[-1][-1]
cell_range = "%s:%s" % (first_cell.coordinate, last_cell.coordinate)
return cell_range
class FilterColumn(object):
__slots__ = ("_vals", "_col_id", "_blank")
def __init__(self, col_id, vals, blank):
self._vals = list(vals)
self.col_id = col_id
self.blank = blank
@property
def col_id(self):
return self._col_id
@col_id.setter
def col_id(self, value):
self._col_id = int(value)
@property
def vals(self):
return self._vals
@property
def blank(self):
return self._blank
@blank.setter
def blank(self, value):
self._blank = bool(int(value)) if value else False
class SortCondition(object):
__slots__ = ("_ref", "_descending")
def __init__(self, ref, descending):
self.ref = ref
self.descending = descending
@property
def ref(self):
"""Return the ref for this sheet."""
return self._ref
@ref.setter
def ref(self, value):
self._ref = normalize_reference(value)
@property
def descending(self):
return self._descending
@descending.setter
def descending(self, value):
self._descending = bool(int(value)) if value else False
class AutoFilter(object):
"""Represents a auto filter.
Don't create auto filters by yourself. It is created by :class:`~openpyxl.worksheet.Worksheet`.
You can use via :attr:`~~openpyxl.worksheet.Worksheet.auto_filter` attribute.
"""
__slots__ = ("_ref", "_filter_columns", "_sort_conditions")
def __init__(self):
self._ref = None
self._filter_columns = {}
self._sort_conditions = []
@property
def ref(self):
"""Return the reference of this auto filter."""
return self._ref
@ref.setter
def ref(self, value):
self._ref = normalize_reference(value)
@property
def filter_columns(self):
"""Return filters for columns."""
return self._filter_columns
def add_filter_column(self, col_id, vals, blank=False):
"""
Add row filter for specified column.
:param col_id: Zero-origin column id. 0 means first column.
:type col_id: int
:param vals: Value list to show.
:type vals: str[]
:param blank: Show rows that have blank cell if True (default=``False``)
:type blank: bool
"""
filter_column = FilterColumn(col_id, vals, blank)
self._filter_columns[filter_column.col_id] = filter_column
return filter_column
@property
def sort_conditions(self):
"""Return sort conditions"""
return self._sort_conditions
def add_sort_condition(self, ref, descending=False):
"""
Add sort condition for cpecified range of cells.
:param ref: range of the cells (e.g. 'A2:A150')
:type ref: string
:param descending: Descending sort order (default=``False``)
:type descending: bool
"""
sort_condition = SortCondition(ref, descending)
self._sort_conditions.append(sort_condition)
return sort_condition
|