aspose-cells-foss 25.12.1__py3-none-any.whl → 26.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aspose_cells/__init__.py +88 -0
- aspose_cells/auto_filter.py +527 -0
- aspose_cells/cell.py +483 -0
- aspose_cells/cell_value_handler.py +319 -0
- aspose_cells/cells.py +779 -0
- aspose_cells/cfb_handler.py +445 -0
- aspose_cells/cfb_writer.py +659 -0
- aspose_cells/cfb_writer_minimal.py +337 -0
- aspose_cells/comment_xml.py +475 -0
- aspose_cells/conditional_format.py +1185 -0
- aspose_cells/csv_handler.py +690 -0
- aspose_cells/data_validation.py +911 -0
- aspose_cells/document_properties.py +356 -0
- aspose_cells/encryption_crypto.py +247 -0
- aspose_cells/encryption_params.py +138 -0
- aspose_cells/hyperlink.py +372 -0
- aspose_cells/json_handler.py +185 -0
- aspose_cells/markdown_handler.py +583 -0
- aspose_cells/shared_strings.py +101 -0
- aspose_cells/style.py +841 -0
- aspose_cells/workbook.py +499 -0
- aspose_cells/workbook_hash_password.py +68 -0
- aspose_cells/workbook_properties.py +712 -0
- aspose_cells/worksheet.py +570 -0
- aspose_cells/worksheet_properties.py +1239 -0
- aspose_cells/xlsx_encryptor.py +403 -0
- aspose_cells/xml_autofilter_loader.py +195 -0
- aspose_cells/xml_autofilter_saver.py +173 -0
- aspose_cells/xml_conditional_format_loader.py +215 -0
- aspose_cells/xml_conditional_format_saver.py +351 -0
- aspose_cells/xml_datavalidation_loader.py +239 -0
- aspose_cells/xml_datavalidation_saver.py +245 -0
- aspose_cells/xml_hyperlink_handler.py +323 -0
- aspose_cells/xml_loader.py +986 -0
- aspose_cells/xml_properties_loader.py +512 -0
- aspose_cells/xml_properties_saver.py +607 -0
- aspose_cells/xml_saver.py +1306 -0
- aspose_cells_foss-26.2.2.dist-info/METADATA +190 -0
- aspose_cells_foss-26.2.2.dist-info/RECORD +41 -0
- {aspose_cells_foss-25.12.1.dist-info → aspose_cells_foss-26.2.2.dist-info}/WHEEL +1 -1
- aspose_cells_foss-26.2.2.dist-info/top_level.txt +1 -0
- aspose/__init__.py +0 -14
- aspose/cells/__init__.py +0 -31
- aspose/cells/cell.py +0 -350
- aspose/cells/constants.py +0 -44
- aspose/cells/converters/__init__.py +0 -13
- aspose/cells/converters/csv_converter.py +0 -55
- aspose/cells/converters/json_converter.py +0 -46
- aspose/cells/converters/markdown_converter.py +0 -453
- aspose/cells/drawing/__init__.py +0 -17
- aspose/cells/drawing/anchor.py +0 -172
- aspose/cells/drawing/collection.py +0 -233
- aspose/cells/drawing/image.py +0 -338
- aspose/cells/formats.py +0 -80
- aspose/cells/formula/__init__.py +0 -10
- aspose/cells/formula/evaluator.py +0 -360
- aspose/cells/formula/functions.py +0 -433
- aspose/cells/formula/tokenizer.py +0 -340
- aspose/cells/io/__init__.py +0 -27
- aspose/cells/io/csv/__init__.py +0 -8
- aspose/cells/io/csv/reader.py +0 -88
- aspose/cells/io/csv/writer.py +0 -98
- aspose/cells/io/factory.py +0 -138
- aspose/cells/io/interfaces.py +0 -48
- aspose/cells/io/json/__init__.py +0 -8
- aspose/cells/io/json/reader.py +0 -126
- aspose/cells/io/json/writer.py +0 -119
- aspose/cells/io/md/__init__.py +0 -8
- aspose/cells/io/md/reader.py +0 -161
- aspose/cells/io/md/writer.py +0 -334
- aspose/cells/io/models.py +0 -64
- aspose/cells/io/xlsx/__init__.py +0 -9
- aspose/cells/io/xlsx/constants.py +0 -312
- aspose/cells/io/xlsx/image_writer.py +0 -311
- aspose/cells/io/xlsx/reader.py +0 -284
- aspose/cells/io/xlsx/writer.py +0 -931
- aspose/cells/plugins/__init__.py +0 -6
- aspose/cells/plugins/docling_backend/__init__.py +0 -7
- aspose/cells/plugins/docling_backend/backend.py +0 -535
- aspose/cells/plugins/markitdown_plugin/__init__.py +0 -15
- aspose/cells/plugins/markitdown_plugin/plugin.py +0 -128
- aspose/cells/range.py +0 -210
- aspose/cells/style.py +0 -287
- aspose/cells/utils/__init__.py +0 -54
- aspose/cells/utils/coordinates.py +0 -68
- aspose/cells/utils/exceptions.py +0 -43
- aspose/cells/utils/validation.py +0 -102
- aspose/cells/workbook.py +0 -352
- aspose/cells/worksheet.py +0 -670
- aspose_cells_foss-25.12.1.dist-info/METADATA +0 -189
- aspose_cells_foss-25.12.1.dist-info/RECORD +0 -53
- aspose_cells_foss-25.12.1.dist-info/entry_points.txt +0 -2
- aspose_cells_foss-25.12.1.dist-info/top_level.txt +0 -1
aspose_cells/__init__.py
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Aspose.Cells for Python
|
|
3
|
+
|
|
4
|
+
A Python library for creating, reading, and modifying Excel files (.xlsx format).
|
|
5
|
+
This library provides a simple API compatible with Aspose.Cells for .NET structure.
|
|
6
|
+
|
|
7
|
+
Main Classes:
|
|
8
|
+
- Workbook: Represents an Excel workbook
|
|
9
|
+
- Worksheet: Represents a worksheet within a workbook
|
|
10
|
+
- Cell: Represents a single cell
|
|
11
|
+
- Cells: Collection of cells in a worksheet
|
|
12
|
+
- Style: Represents cell formatting styles
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from .workbook import Workbook, SaveFormat
|
|
16
|
+
from .worksheet import Worksheet
|
|
17
|
+
from .cell import Cell
|
|
18
|
+
from .cells import Cells
|
|
19
|
+
from .style import Style, Font, NumberFormat
|
|
20
|
+
from .encryption_params import (
|
|
21
|
+
AgileEncryptionParameters,
|
|
22
|
+
StandardEncryptionParameters,
|
|
23
|
+
CipherAlgorithm,
|
|
24
|
+
HashAlgorithm,
|
|
25
|
+
get_default_encryption_params
|
|
26
|
+
)
|
|
27
|
+
from .xlsx_encryptor import encrypt_xlsx, decrypt_xlsx
|
|
28
|
+
from .data_validation import (
|
|
29
|
+
DataValidation,
|
|
30
|
+
DataValidationCollection,
|
|
31
|
+
DataValidationType,
|
|
32
|
+
DataValidationOperator,
|
|
33
|
+
DataValidationAlertStyle,
|
|
34
|
+
DataValidationImeMode
|
|
35
|
+
)
|
|
36
|
+
from .csv_handler import (
|
|
37
|
+
CSVHandler,
|
|
38
|
+
CSVLoadOptions,
|
|
39
|
+
CSVSaveOptions,
|
|
40
|
+
load_csv_workbook,
|
|
41
|
+
save_workbook_as_csv
|
|
42
|
+
)
|
|
43
|
+
from .markdown_handler import (
|
|
44
|
+
MarkdownHandler,
|
|
45
|
+
MarkdownSaveOptions,
|
|
46
|
+
save_workbook_as_markdown
|
|
47
|
+
)
|
|
48
|
+
from .json_handler import (
|
|
49
|
+
JsonHandler,
|
|
50
|
+
JsonSaveOptions,
|
|
51
|
+
save_workbook_as_json
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
__version__ = "26.2.2"
|
|
55
|
+
__all__ = [
|
|
56
|
+
"Workbook",
|
|
57
|
+
"SaveFormat",
|
|
58
|
+
"Worksheet",
|
|
59
|
+
"Cell",
|
|
60
|
+
"Cells",
|
|
61
|
+
"Style",
|
|
62
|
+
"Font",
|
|
63
|
+
"NumberFormat",
|
|
64
|
+
"AgileEncryptionParameters",
|
|
65
|
+
"StandardEncryptionParameters",
|
|
66
|
+
"CipherAlgorithm",
|
|
67
|
+
"HashAlgorithm",
|
|
68
|
+
"get_default_encryption_params",
|
|
69
|
+
"encrypt_xlsx",
|
|
70
|
+
"decrypt_xlsx",
|
|
71
|
+
"DataValidation",
|
|
72
|
+
"DataValidationCollection",
|
|
73
|
+
"DataValidationType",
|
|
74
|
+
"DataValidationOperator",
|
|
75
|
+
"DataValidationAlertStyle",
|
|
76
|
+
"DataValidationImeMode",
|
|
77
|
+
"CSVHandler",
|
|
78
|
+
"CSVLoadOptions",
|
|
79
|
+
"CSVSaveOptions",
|
|
80
|
+
"load_csv_workbook",
|
|
81
|
+
"save_workbook_as_csv",
|
|
82
|
+
"MarkdownHandler",
|
|
83
|
+
"MarkdownSaveOptions",
|
|
84
|
+
"save_workbook_as_markdown",
|
|
85
|
+
"JsonHandler",
|
|
86
|
+
"JsonSaveOptions",
|
|
87
|
+
"save_workbook_as_json",
|
|
88
|
+
]
|
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Aspose.Cells for Python - AutoFilter Module
|
|
3
|
+
|
|
4
|
+
This module provides the AutoFilter class which represents auto filters in Excel worksheets.
|
|
5
|
+
The AutoFilter class provides methods for applying and managing filters on data ranges.
|
|
6
|
+
|
|
7
|
+
Compatible with Aspose.Cells for .NET API structure.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class FilterColumn:
|
|
12
|
+
"""
|
|
13
|
+
Represents a filter column in an auto filter.
|
|
14
|
+
|
|
15
|
+
A FilterColumn represents filtering settings for a specific column in the filtered range.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def __init__(self, col_id):
|
|
19
|
+
"""
|
|
20
|
+
Initializes a new instance of the FilterColumn class.
|
|
21
|
+
|
|
22
|
+
Args:
|
|
23
|
+
col_id (int): Zero-based column index in the filter range.
|
|
24
|
+
"""
|
|
25
|
+
self._col_id = col_id
|
|
26
|
+
self._filters = [] # List of filter values
|
|
27
|
+
self._custom_filters = [] # List of custom filter criteria
|
|
28
|
+
self._color_filter = None # Color filter settings
|
|
29
|
+
self._dynamic_filter = None # Dynamic filter settings
|
|
30
|
+
self._top10_filter = None # Top 10 filter settings
|
|
31
|
+
self._filter_button = True # Whether filter button is visible
|
|
32
|
+
|
|
33
|
+
@property
|
|
34
|
+
def col_id(self):
|
|
35
|
+
"""
|
|
36
|
+
Gets the zero-based column index.
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
int: Zero-based column index.
|
|
40
|
+
"""
|
|
41
|
+
return self._col_id
|
|
42
|
+
|
|
43
|
+
@property
|
|
44
|
+
def filters(self):
|
|
45
|
+
"""
|
|
46
|
+
Gets the list of filter values.
|
|
47
|
+
|
|
48
|
+
Returns:
|
|
49
|
+
list: List of filter values.
|
|
50
|
+
"""
|
|
51
|
+
return self._filters
|
|
52
|
+
|
|
53
|
+
@property
|
|
54
|
+
def custom_filters(self):
|
|
55
|
+
"""
|
|
56
|
+
Gets the list of custom filter criteria.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
list: List of custom filter criteria tuples (operator, value).
|
|
60
|
+
"""
|
|
61
|
+
return self._custom_filters
|
|
62
|
+
|
|
63
|
+
@property
|
|
64
|
+
def color_filter(self):
|
|
65
|
+
"""
|
|
66
|
+
Gets or sets the color filter settings.
|
|
67
|
+
|
|
68
|
+
Returns:
|
|
69
|
+
dict or None: Color filter settings with keys 'color' and 'cell_color' (bool).
|
|
70
|
+
"""
|
|
71
|
+
return self._color_filter
|
|
72
|
+
|
|
73
|
+
@color_filter.setter
|
|
74
|
+
def color_filter(self, value):
|
|
75
|
+
"""
|
|
76
|
+
Sets the color filter settings.
|
|
77
|
+
|
|
78
|
+
Args:
|
|
79
|
+
value (dict): Color filter settings with keys 'color' and 'cell_color' (bool).
|
|
80
|
+
"""
|
|
81
|
+
self._color_filter = value
|
|
82
|
+
|
|
83
|
+
@property
|
|
84
|
+
def dynamic_filter(self):
|
|
85
|
+
"""
|
|
86
|
+
Gets or sets the dynamic filter settings.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
dict or None: Dynamic filter settings with keys 'type' and 'value'.
|
|
90
|
+
"""
|
|
91
|
+
return self._dynamic_filter
|
|
92
|
+
|
|
93
|
+
@dynamic_filter.setter
|
|
94
|
+
def dynamic_filter(self, value):
|
|
95
|
+
"""
|
|
96
|
+
Sets the dynamic filter settings.
|
|
97
|
+
|
|
98
|
+
Args:
|
|
99
|
+
value (dict): Dynamic filter settings with keys 'type' and 'value'.
|
|
100
|
+
"""
|
|
101
|
+
self._dynamic_filter = value
|
|
102
|
+
|
|
103
|
+
@property
|
|
104
|
+
def top10_filter(self):
|
|
105
|
+
"""
|
|
106
|
+
Gets or sets the top 10 filter settings.
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
dict or None: Top 10 filter settings with keys 'top', 'percent', and 'val'.
|
|
110
|
+
"""
|
|
111
|
+
return self._top10_filter
|
|
112
|
+
|
|
113
|
+
@top10_filter.setter
|
|
114
|
+
def top10_filter(self, value):
|
|
115
|
+
"""
|
|
116
|
+
Sets the top 10 filter settings.
|
|
117
|
+
|
|
118
|
+
Args:
|
|
119
|
+
value (dict): Top 10 filter settings with keys 'top', 'percent', and 'val'.
|
|
120
|
+
"""
|
|
121
|
+
self._top10_filter = value
|
|
122
|
+
|
|
123
|
+
@property
|
|
124
|
+
def filter_button(self):
|
|
125
|
+
"""
|
|
126
|
+
Gets or sets whether the filter button is visible.
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
bool: True if filter button is visible, False otherwise.
|
|
130
|
+
"""
|
|
131
|
+
return self._filter_button
|
|
132
|
+
|
|
133
|
+
@filter_button.setter
|
|
134
|
+
def filter_button(self, value):
|
|
135
|
+
"""
|
|
136
|
+
Sets whether the filter button is visible.
|
|
137
|
+
|
|
138
|
+
Args:
|
|
139
|
+
value (bool): True to show filter button, False to hide.
|
|
140
|
+
"""
|
|
141
|
+
self._filter_button = value
|
|
142
|
+
|
|
143
|
+
def add_filter(self, value):
|
|
144
|
+
"""
|
|
145
|
+
Adds a filter value to this column.
|
|
146
|
+
|
|
147
|
+
Args:
|
|
148
|
+
value: The value to filter by.
|
|
149
|
+
|
|
150
|
+
Examples:
|
|
151
|
+
>>> filter_col.add_filter("Apple")
|
|
152
|
+
>>> filter_col.add_filter(100)
|
|
153
|
+
"""
|
|
154
|
+
self._filters.append(value)
|
|
155
|
+
|
|
156
|
+
def add_custom_filter(self, operator, value):
|
|
157
|
+
"""
|
|
158
|
+
Adds a custom filter criterion to this column.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
operator (str): The operator ('equal', 'notEqual', 'greaterThan', 'lessThan',
|
|
162
|
+
'greaterThanOrEqual', 'lessThanOrEqual', 'contains', 'notContains',
|
|
163
|
+
'beginsWith', 'endsWith').
|
|
164
|
+
value: The value to compare against.
|
|
165
|
+
|
|
166
|
+
Examples:
|
|
167
|
+
>>> filter_col.add_custom_filter('greaterThan', 50)
|
|
168
|
+
>>> filter_col.add_custom_filter('contains', 'test')
|
|
169
|
+
"""
|
|
170
|
+
self._custom_filters.append((operator, value))
|
|
171
|
+
|
|
172
|
+
def clear_filters(self):
|
|
173
|
+
"""
|
|
174
|
+
Clears all filters from this column.
|
|
175
|
+
|
|
176
|
+
Examples:
|
|
177
|
+
>>> filter_col.clear_filters()
|
|
178
|
+
"""
|
|
179
|
+
self._filters = []
|
|
180
|
+
self._custom_filters = []
|
|
181
|
+
self._color_filter = None
|
|
182
|
+
self._dynamic_filter = None
|
|
183
|
+
self._top10_filter = None
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
class AutoFilter:
|
|
187
|
+
"""
|
|
188
|
+
Represents auto filters in a worksheet.
|
|
189
|
+
|
|
190
|
+
The AutoFilter class provides methods and properties for applying and managing
|
|
191
|
+
filters on data ranges in a worksheet.
|
|
192
|
+
|
|
193
|
+
Examples:
|
|
194
|
+
>>> from aspose_cells import Workbook
|
|
195
|
+
>>> wb = Workbook()
|
|
196
|
+
>>> ws = wb.worksheets[0]
|
|
197
|
+
>>> ws.cells['A1'].value = "Name"
|
|
198
|
+
>>> ws.cells['B1'].value = "Age"
|
|
199
|
+
>>> ws.auto_filter.range = "A1:B10"
|
|
200
|
+
>>> ws.auto_filter.filter(0, ["Alice", "Bob"])
|
|
201
|
+
"""
|
|
202
|
+
|
|
203
|
+
def __init__(self):
|
|
204
|
+
"""
|
|
205
|
+
Initializes a new instance of the AutoFilter class.
|
|
206
|
+
"""
|
|
207
|
+
self._range = None # Filter range in A1 notation (e.g., "A1:D10")
|
|
208
|
+
self._filter_columns = {} # Dictionary mapping col_id to FilterColumn objects
|
|
209
|
+
self._sort_state = None # Sort state settings
|
|
210
|
+
|
|
211
|
+
@property
|
|
212
|
+
def range(self):
|
|
213
|
+
"""
|
|
214
|
+
Gets or sets the filter range.
|
|
215
|
+
|
|
216
|
+
Returns:
|
|
217
|
+
str or None: Filter range in A1 notation (e.g., "A1:D10").
|
|
218
|
+
|
|
219
|
+
Examples:
|
|
220
|
+
>>> ws.auto_filter.range = "A1:D10"
|
|
221
|
+
>>> print(ws.auto_filter.range)
|
|
222
|
+
"""
|
|
223
|
+
return self._range
|
|
224
|
+
|
|
225
|
+
@range.setter
|
|
226
|
+
def range(self, value):
|
|
227
|
+
"""
|
|
228
|
+
Sets the filter range.
|
|
229
|
+
|
|
230
|
+
Args:
|
|
231
|
+
value (str): Filter range in A1 notation (e.g., "A1:D10").
|
|
232
|
+
|
|
233
|
+
Examples:
|
|
234
|
+
>>> ws.auto_filter.range = "A1:D10"
|
|
235
|
+
"""
|
|
236
|
+
self._range = value
|
|
237
|
+
|
|
238
|
+
@property
|
|
239
|
+
def filter_columns(self):
|
|
240
|
+
"""
|
|
241
|
+
Gets the collection of filter columns.
|
|
242
|
+
|
|
243
|
+
Returns:
|
|
244
|
+
dict: Dictionary mapping col_id to FilterColumn objects.
|
|
245
|
+
"""
|
|
246
|
+
return self._filter_columns
|
|
247
|
+
|
|
248
|
+
@property
|
|
249
|
+
def sort_state(self):
|
|
250
|
+
"""
|
|
251
|
+
Gets or sets the sort state settings.
|
|
252
|
+
|
|
253
|
+
Returns:
|
|
254
|
+
dict or None: Sort state settings with keys 'column_offset', 'sort_order', etc.
|
|
255
|
+
"""
|
|
256
|
+
return self._sort_state
|
|
257
|
+
|
|
258
|
+
@sort_state.setter
|
|
259
|
+
def sort_state(self, value):
|
|
260
|
+
"""
|
|
261
|
+
Sets the sort state settings.
|
|
262
|
+
|
|
263
|
+
Args:
|
|
264
|
+
value (dict): Sort state settings with keys 'column_offset', 'sort_order', etc.
|
|
265
|
+
"""
|
|
266
|
+
self._sort_state = value
|
|
267
|
+
|
|
268
|
+
def set_range(self, start_row, start_col, end_row, end_col):
|
|
269
|
+
"""
|
|
270
|
+
Sets the filter range using row and column indices.
|
|
271
|
+
|
|
272
|
+
Args:
|
|
273
|
+
start_row (int): 1-based starting row number.
|
|
274
|
+
start_col (int or str): 1-based starting column number or letter (e.g., 1 or 'A').
|
|
275
|
+
end_row (int): 1-based ending row number.
|
|
276
|
+
end_col (int or str): 1-based ending column number or letter (e.g., 4 or 'D').
|
|
277
|
+
|
|
278
|
+
Examples:
|
|
279
|
+
>>> ws.auto_filter.set_range(1, 1, 10, 4) # A1:D10
|
|
280
|
+
>>> ws.auto_filter.set_range(1, 'A', 10, 'D') # A1:D10
|
|
281
|
+
"""
|
|
282
|
+
from .cells import Cells
|
|
283
|
+
|
|
284
|
+
# Convert column to letter if necessary
|
|
285
|
+
if isinstance(start_col, int):
|
|
286
|
+
start_col_letter = Cells.column_letter_from_index(start_col)
|
|
287
|
+
else:
|
|
288
|
+
start_col_letter = start_col.upper()
|
|
289
|
+
|
|
290
|
+
if isinstance(end_col, int):
|
|
291
|
+
end_col_letter = Cells.column_letter_from_index(end_col)
|
|
292
|
+
else:
|
|
293
|
+
end_col_letter = end_col.upper()
|
|
294
|
+
|
|
295
|
+
self._range = f"{start_col_letter}{start_row}:{end_col_letter}{end_row}"
|
|
296
|
+
|
|
297
|
+
def filter(self, col_index, values):
|
|
298
|
+
"""
|
|
299
|
+
Applies a filter to a specific column.
|
|
300
|
+
|
|
301
|
+
Args:
|
|
302
|
+
col_index (int): Zero-based column index within the filter range.
|
|
303
|
+
values (list): List of values to filter by.
|
|
304
|
+
|
|
305
|
+
Examples:
|
|
306
|
+
>>> ws.auto_filter.filter(0, ["Apple", "Banana"]) # Filter first column
|
|
307
|
+
>>> ws.auto_filter.filter(1, [10, 20, 30]) # Filter second column
|
|
308
|
+
"""
|
|
309
|
+
if col_index not in self._filter_columns:
|
|
310
|
+
self._filter_columns[col_index] = FilterColumn(col_index)
|
|
311
|
+
|
|
312
|
+
filter_col = self._filter_columns[col_index]
|
|
313
|
+
filter_col._filters = list(values)
|
|
314
|
+
|
|
315
|
+
def add_filter(self, col_index, value):
|
|
316
|
+
"""
|
|
317
|
+
Adds a filter value to a specific column.
|
|
318
|
+
|
|
319
|
+
Args:
|
|
320
|
+
col_index (int): Zero-based column index within the filter range.
|
|
321
|
+
value: The value to filter by.
|
|
322
|
+
|
|
323
|
+
Examples:
|
|
324
|
+
>>> ws.auto_filter.add_filter(0, "Apple")
|
|
325
|
+
>>> ws.auto_filter.add_filter(1, 100)
|
|
326
|
+
"""
|
|
327
|
+
if col_index not in self._filter_columns:
|
|
328
|
+
self._filter_columns[col_index] = FilterColumn(col_index)
|
|
329
|
+
|
|
330
|
+
self._filter_columns[col_index].add_filter(value)
|
|
331
|
+
|
|
332
|
+
def custom_filter(self, col_index, operator, value):
|
|
333
|
+
"""
|
|
334
|
+
Applies a custom filter to a specific column.
|
|
335
|
+
|
|
336
|
+
Args:
|
|
337
|
+
col_index (int): Zero-based column index within the filter range.
|
|
338
|
+
operator (str): The operator ('equal', 'notEqual', 'greaterThan', 'lessThan',
|
|
339
|
+
'greaterThanOrEqual', 'lessThanOrEqual', 'contains', 'notContains',
|
|
340
|
+
'beginsWith', 'endsWith').
|
|
341
|
+
value: The value to compare against.
|
|
342
|
+
|
|
343
|
+
Examples:
|
|
344
|
+
>>> ws.auto_filter.custom_filter(0, 'greaterThan', 50)
|
|
345
|
+
>>> ws.auto_filter.custom_filter(1, 'contains', 'test')
|
|
346
|
+
"""
|
|
347
|
+
if col_index not in self._filter_columns:
|
|
348
|
+
self._filter_columns[col_index] = FilterColumn(col_index)
|
|
349
|
+
|
|
350
|
+
self._filter_columns[col_index].add_custom_filter(operator, value)
|
|
351
|
+
|
|
352
|
+
def filter_by_color(self, col_index, color, cell_color=True):
|
|
353
|
+
"""
|
|
354
|
+
Applies a color filter to a specific column.
|
|
355
|
+
|
|
356
|
+
Args:
|
|
357
|
+
col_index (int): Zero-based column index within the filter range.
|
|
358
|
+
color (str): RGB hex color string in AARRGGBB format.
|
|
359
|
+
cell_color (bool): True to filter by cell color, False to filter by font color.
|
|
360
|
+
|
|
361
|
+
Examples:
|
|
362
|
+
>>> ws.auto_filter.filter_by_color(0, 'FFFF0000') # Filter by red cell color
|
|
363
|
+
>>> ws.auto_filter.filter_by_color(1, 'FF0000FF', False) # Filter by blue font color
|
|
364
|
+
"""
|
|
365
|
+
if col_index not in self._filter_columns:
|
|
366
|
+
self._filter_columns[col_index] = FilterColumn(col_index)
|
|
367
|
+
|
|
368
|
+
self._filter_columns[col_index].color_filter = {
|
|
369
|
+
'color': color,
|
|
370
|
+
'cell_color': cell_color
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
def filter_top10(self, col_index, top=True, percent=False, val=10):
|
|
374
|
+
"""
|
|
375
|
+
Applies a top 10 filter to a specific column.
|
|
376
|
+
|
|
377
|
+
Args:
|
|
378
|
+
col_index (int): Zero-based column index within the filter range.
|
|
379
|
+
top (bool): True for top items, False for bottom items.
|
|
380
|
+
percent (bool): True for percentage, False for count.
|
|
381
|
+
val (int): The value (count or percentage).
|
|
382
|
+
|
|
383
|
+
Examples:
|
|
384
|
+
>>> ws.auto_filter.filter_top10(0) # Top 10 items
|
|
385
|
+
>>> ws.auto_filter.filter_top10(1, top=False) # Bottom 10 items
|
|
386
|
+
>>> ws.auto_filter.filter_top10(2, percent=True, val=20) # Top 20%
|
|
387
|
+
"""
|
|
388
|
+
if col_index not in self._filter_columns:
|
|
389
|
+
self._filter_columns[col_index] = FilterColumn(col_index)
|
|
390
|
+
|
|
391
|
+
self._filter_columns[col_index].top10_filter = {
|
|
392
|
+
'top': top,
|
|
393
|
+
'percent': percent,
|
|
394
|
+
'val': val
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
def filter_dynamic(self, col_index, filter_type, value=None):
|
|
398
|
+
"""
|
|
399
|
+
Applies a dynamic filter to a specific column.
|
|
400
|
+
|
|
401
|
+
Args:
|
|
402
|
+
col_index (int): Zero-based column index within the filter range.
|
|
403
|
+
filter_type (str): The dynamic filter type ('aboveAverage', 'belowAverage',
|
|
404
|
+
'lastMonth', 'lastQuarter', 'lastWeek', 'lastYear',
|
|
405
|
+
'nextMonth', 'nextQuarter', 'nextWeek', 'nextYear',
|
|
406
|
+
'thisMonth', 'thisQuarter', 'thisWeek', 'thisYear',
|
|
407
|
+
'today', 'tomorrow', 'yesterday', 'yearToDate').
|
|
408
|
+
value: Optional value for the filter.
|
|
409
|
+
|
|
410
|
+
Examples:
|
|
411
|
+
>>> ws.auto_filter.filter_dynamic(0, 'aboveAverage')
|
|
412
|
+
>>> ws.auto_filter.filter_dynamic(1, 'lastMonth')
|
|
413
|
+
"""
|
|
414
|
+
if col_index not in self._filter_columns:
|
|
415
|
+
self._filter_columns[col_index] = FilterColumn(col_index)
|
|
416
|
+
|
|
417
|
+
self._filter_columns[col_index].dynamic_filter = {
|
|
418
|
+
'type': filter_type,
|
|
419
|
+
'value': value
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
def clear_column_filter(self, col_index):
|
|
423
|
+
"""
|
|
424
|
+
Clears the filter for a specific column.
|
|
425
|
+
|
|
426
|
+
Args:
|
|
427
|
+
col_index (int): Zero-based column index within the filter range.
|
|
428
|
+
|
|
429
|
+
Examples:
|
|
430
|
+
>>> ws.auto_filter.clear_column_filter(0)
|
|
431
|
+
"""
|
|
432
|
+
if col_index in self._filter_columns:
|
|
433
|
+
self._filter_columns[col_index].clear_filters()
|
|
434
|
+
|
|
435
|
+
def clear_all_filters(self):
|
|
436
|
+
"""
|
|
437
|
+
Clears all filters.
|
|
438
|
+
|
|
439
|
+
Examples:
|
|
440
|
+
>>> ws.auto_filter.clear_all_filters()
|
|
441
|
+
"""
|
|
442
|
+
self._filter_columns = {}
|
|
443
|
+
|
|
444
|
+
def remove(self):
|
|
445
|
+
"""
|
|
446
|
+
Removes the auto filter from the worksheet.
|
|
447
|
+
|
|
448
|
+
Examples:
|
|
449
|
+
>>> ws.auto_filter.remove()
|
|
450
|
+
"""
|
|
451
|
+
self._range = None
|
|
452
|
+
self._filter_columns = {}
|
|
453
|
+
self._sort_state = None
|
|
454
|
+
|
|
455
|
+
def show_filter_button(self, col_index, show=True):
|
|
456
|
+
"""
|
|
457
|
+
Shows or hides the filter button for a specific column.
|
|
458
|
+
|
|
459
|
+
Args:
|
|
460
|
+
col_index (int): Zero-based column index within the filter range.
|
|
461
|
+
show (bool): True to show, False to hide.
|
|
462
|
+
|
|
463
|
+
Examples:
|
|
464
|
+
>>> ws.auto_filter.show_filter_button(0, False) # Hide filter button
|
|
465
|
+
"""
|
|
466
|
+
if col_index not in self._filter_columns:
|
|
467
|
+
self._filter_columns[col_index] = FilterColumn(col_index)
|
|
468
|
+
|
|
469
|
+
self._filter_columns[col_index].filter_button = show
|
|
470
|
+
|
|
471
|
+
def sort(self, col_index, ascending=True):
|
|
472
|
+
"""
|
|
473
|
+
Sets the sort order for a specific column.
|
|
474
|
+
|
|
475
|
+
Args:
|
|
476
|
+
col_index (int): Zero-based column index within the filter range.
|
|
477
|
+
ascending (bool): True for ascending order, False for descending.
|
|
478
|
+
|
|
479
|
+
Examples:
|
|
480
|
+
>>> ws.auto_filter.sort(0, True) # Sort first column ascending
|
|
481
|
+
>>> ws.auto_filter.sort(1, False) # Sort second column descending
|
|
482
|
+
"""
|
|
483
|
+
self._sort_state = {
|
|
484
|
+
'column_index': col_index,
|
|
485
|
+
'descending': not ascending
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
def get_filter_column(self, col_index):
|
|
489
|
+
"""
|
|
490
|
+
Gets the filter column for a specific column index.
|
|
491
|
+
|
|
492
|
+
Args:
|
|
493
|
+
col_index (int): Zero-based column index within the filter range.
|
|
494
|
+
|
|
495
|
+
Returns:
|
|
496
|
+
FilterColumn or None: The FilterColumn object, or None if not found.
|
|
497
|
+
|
|
498
|
+
Examples:
|
|
499
|
+
>>> filter_col = ws.auto_filter.get_filter_column(0)
|
|
500
|
+
>>> if filter_col:
|
|
501
|
+
... print(filter_col.filters)
|
|
502
|
+
"""
|
|
503
|
+
return self._filter_columns.get(col_index)
|
|
504
|
+
|
|
505
|
+
def has_filter(self, col_index):
|
|
506
|
+
"""
|
|
507
|
+
Checks if a specific column has filters applied.
|
|
508
|
+
|
|
509
|
+
Args:
|
|
510
|
+
col_index (int): Zero-based column index within the filter range.
|
|
511
|
+
|
|
512
|
+
Returns:
|
|
513
|
+
bool: True if the column has filters, False otherwise.
|
|
514
|
+
|
|
515
|
+
Examples:
|
|
516
|
+
>>> if ws.auto_filter.has_filter(0):
|
|
517
|
+
... print("Column 0 has filters")
|
|
518
|
+
"""
|
|
519
|
+
if col_index not in self._filter_columns:
|
|
520
|
+
return False
|
|
521
|
+
|
|
522
|
+
filter_col = self._filter_columns[col_index]
|
|
523
|
+
return (len(filter_col.filters) > 0 or
|
|
524
|
+
len(filter_col.custom_filters) > 0 or
|
|
525
|
+
filter_col.color_filter is not None or
|
|
526
|
+
filter_col.dynamic_filter is not None or
|
|
527
|
+
filter_col.top10_filter is not None)
|