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
|
@@ -0,0 +1,570 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Aspose.Cells for Python - Worksheet Module
|
|
3
|
+
|
|
4
|
+
This module provides the Worksheet class which represents a single worksheet in an Excel workbook.
|
|
5
|
+
The Worksheet class provides methods to manage cells, ranges, and worksheet properties.
|
|
6
|
+
|
|
7
|
+
Compatible with Aspose.Cells for .NET API structure.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from .cells import Cells
|
|
11
|
+
from .cell import Cell
|
|
12
|
+
from .auto_filter import AutoFilter
|
|
13
|
+
from .conditional_format import ConditionalFormatCollection
|
|
14
|
+
from .worksheet_properties import WorksheetProperties
|
|
15
|
+
from .hyperlink import Hyperlinks
|
|
16
|
+
from .data_validation import DataValidationCollection
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class SheetProtectionDictWrapper:
|
|
20
|
+
"""
|
|
21
|
+
Dictionary-like wrapper around SheetProtection for backward compatibility.
|
|
22
|
+
|
|
23
|
+
This wrapper allows accessing SheetProtection properties using dictionary syntax
|
|
24
|
+
while maintaining backward compatibility with existing code that uses ws.protection['key'].
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
def __init__(self, sheet_protection):
|
|
28
|
+
"""
|
|
29
|
+
Initialize wrapper with a SheetProtection object.
|
|
30
|
+
|
|
31
|
+
Args:
|
|
32
|
+
sheet_protection: The SheetProtection object to wrap.
|
|
33
|
+
"""
|
|
34
|
+
self._protection = sheet_protection
|
|
35
|
+
|
|
36
|
+
def __getitem__(self, key):
|
|
37
|
+
"""Get protection setting by key."""
|
|
38
|
+
if key == 'protected':
|
|
39
|
+
return self._protection.sheet
|
|
40
|
+
elif key == 'password':
|
|
41
|
+
return self._protection.password
|
|
42
|
+
elif key == 'sheet':
|
|
43
|
+
return self._protection.sheet
|
|
44
|
+
elif key == 'objects':
|
|
45
|
+
return self._protection.objects
|
|
46
|
+
elif key == 'scenarios':
|
|
47
|
+
return self._protection.scenarios
|
|
48
|
+
elif key == 'format_cells':
|
|
49
|
+
return self._protection.format_cells
|
|
50
|
+
elif key == 'format_columns':
|
|
51
|
+
return self._protection.format_columns
|
|
52
|
+
elif key == 'format_rows':
|
|
53
|
+
return self._protection.format_rows
|
|
54
|
+
elif key == 'insert_columns':
|
|
55
|
+
return self._protection.insert_columns
|
|
56
|
+
elif key == 'insert_rows':
|
|
57
|
+
return self._protection.insert_rows
|
|
58
|
+
elif key == 'insert_hyperlinks':
|
|
59
|
+
return self._protection.insert_hyperlinks
|
|
60
|
+
elif key == 'delete_columns':
|
|
61
|
+
return self._protection.delete_columns
|
|
62
|
+
elif key == 'delete_rows':
|
|
63
|
+
return self._protection.delete_rows
|
|
64
|
+
elif key == 'select_locked_cells':
|
|
65
|
+
return self._protection.select_locked_cells
|
|
66
|
+
elif key == 'select_unlocked_cells':
|
|
67
|
+
return self._protection.select_unlocked_cells
|
|
68
|
+
elif key == 'sort':
|
|
69
|
+
return self._protection.sort
|
|
70
|
+
elif key == 'auto_filter':
|
|
71
|
+
return self._protection.auto_filter
|
|
72
|
+
elif key == 'pivot_tables':
|
|
73
|
+
return self._protection.pivot_tables
|
|
74
|
+
else:
|
|
75
|
+
raise KeyError(f"Unknown protection key: {key}")
|
|
76
|
+
|
|
77
|
+
def __setitem__(self, key, value):
|
|
78
|
+
"""Set protection setting by key."""
|
|
79
|
+
if key == 'protected':
|
|
80
|
+
self._protection.sheet = value
|
|
81
|
+
elif key == 'password':
|
|
82
|
+
self._protection.password = value
|
|
83
|
+
elif key == 'sheet':
|
|
84
|
+
self._protection.sheet = value
|
|
85
|
+
elif key == 'objects':
|
|
86
|
+
self._protection.objects = value
|
|
87
|
+
elif key == 'scenarios':
|
|
88
|
+
self._protection.scenarios = value
|
|
89
|
+
elif key == 'format_cells':
|
|
90
|
+
self._protection.format_cells = value
|
|
91
|
+
elif key == 'format_columns':
|
|
92
|
+
self._protection.format_columns = value
|
|
93
|
+
elif key == 'format_rows':
|
|
94
|
+
self._protection.format_rows = value
|
|
95
|
+
elif key == 'insert_columns':
|
|
96
|
+
self._protection.insert_columns = value
|
|
97
|
+
elif key == 'insert_rows':
|
|
98
|
+
self._protection.insert_rows = value
|
|
99
|
+
elif key == 'insert_hyperlinks':
|
|
100
|
+
self._protection.insert_hyperlinks = value
|
|
101
|
+
elif key == 'delete_columns':
|
|
102
|
+
self._protection.delete_columns = value
|
|
103
|
+
elif key == 'delete_rows':
|
|
104
|
+
self._protection.delete_rows = value
|
|
105
|
+
elif key == 'select_locked_cells':
|
|
106
|
+
self._protection.select_locked_cells = value
|
|
107
|
+
elif key == 'select_unlocked_cells':
|
|
108
|
+
self._protection.select_unlocked_cells = value
|
|
109
|
+
elif key == 'sort':
|
|
110
|
+
self._protection.sort = value
|
|
111
|
+
elif key == 'auto_filter':
|
|
112
|
+
self._protection.auto_filter = value
|
|
113
|
+
elif key == 'pivot_tables':
|
|
114
|
+
self._protection.pivot_tables = value
|
|
115
|
+
else:
|
|
116
|
+
raise KeyError(f"Unknown protection key: {key}")
|
|
117
|
+
|
|
118
|
+
def get(self, key, default=None):
|
|
119
|
+
"""Get protection setting with default value."""
|
|
120
|
+
try:
|
|
121
|
+
return self[key]
|
|
122
|
+
except KeyError:
|
|
123
|
+
return default
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
class Worksheet:
|
|
127
|
+
"""
|
|
128
|
+
Represents a single worksheet in an Excel workbook.
|
|
129
|
+
|
|
130
|
+
The Worksheet class provides access to cells, ranges, and worksheet properties
|
|
131
|
+
such as name, visibility, protection, and page setup settings.
|
|
132
|
+
|
|
133
|
+
Examples:
|
|
134
|
+
>>> wb = Workbook()
|
|
135
|
+
>>> ws = wb.worksheets[0]
|
|
136
|
+
>>> ws.name = "MySheet"
|
|
137
|
+
>>> ws.cells["A1"].value = "Hello"
|
|
138
|
+
"""
|
|
139
|
+
|
|
140
|
+
def __init__(self, name="Sheet1"):
|
|
141
|
+
"""
|
|
142
|
+
Initializes a new instance of the Worksheet class.
|
|
143
|
+
|
|
144
|
+
Args:
|
|
145
|
+
name (str, optional): Name of the worksheet. Defaults to "Sheet1".
|
|
146
|
+
"""
|
|
147
|
+
self._name = name
|
|
148
|
+
self._cells = Cells(self)
|
|
149
|
+
self._visible = True
|
|
150
|
+
self._tab_color = None
|
|
151
|
+
self._auto_filter = AutoFilter() # Auto filter settings
|
|
152
|
+
self._conditional_formats = ConditionalFormatCollection() # Conditional formatting
|
|
153
|
+
self._data_validations = DataValidationCollection() # Data validation rules
|
|
154
|
+
self._properties = WorksheetProperties() # Worksheet properties
|
|
155
|
+
self._hyperlinks = Hyperlinks(self) # Hyperlinks collection
|
|
156
|
+
self._row_heights = {} # Row index -> height (points)
|
|
157
|
+
self._column_widths = {} # Column index -> width (characters)
|
|
158
|
+
self._hidden_rows = set() # Set of hidden row indices
|
|
159
|
+
self._hidden_columns = set() # Set of hidden column indices
|
|
160
|
+
|
|
161
|
+
# Page setup settings
|
|
162
|
+
self._page_setup = {
|
|
163
|
+
'orientation': None, # 'portrait' or 'landscape'
|
|
164
|
+
'paper_size': None, # Integer paper size
|
|
165
|
+
'scale': None, # Integer scale (10-400)
|
|
166
|
+
'fit_to_width': None, # Integer number of pages
|
|
167
|
+
'fit_to_height': None, # Integer number of pages
|
|
168
|
+
'fit_to_page': False # Boolean fit to page
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
# Page margins (in inches)
|
|
172
|
+
self._page_margins = {
|
|
173
|
+
'left': 0.75,
|
|
174
|
+
'right': 0.75,
|
|
175
|
+
'top': 1.0,
|
|
176
|
+
'bottom': 1.0,
|
|
177
|
+
'header': 0.5,
|
|
178
|
+
'footer': 0.5
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
# Properties
|
|
182
|
+
|
|
183
|
+
@property
|
|
184
|
+
def name(self):
|
|
185
|
+
"""
|
|
186
|
+
Gets or sets the name of the worksheet.
|
|
187
|
+
|
|
188
|
+
Returns:
|
|
189
|
+
str: The name of the worksheet.
|
|
190
|
+
"""
|
|
191
|
+
return self._name
|
|
192
|
+
|
|
193
|
+
@name.setter
|
|
194
|
+
def name(self, value):
|
|
195
|
+
"""
|
|
196
|
+
Sets the name of the worksheet.
|
|
197
|
+
|
|
198
|
+
Args:
|
|
199
|
+
value (str): The new name for the worksheet.
|
|
200
|
+
"""
|
|
201
|
+
self._name = value
|
|
202
|
+
|
|
203
|
+
def rename(self, new_name):
|
|
204
|
+
"""
|
|
205
|
+
Renames the worksheet.
|
|
206
|
+
|
|
207
|
+
Args:
|
|
208
|
+
new_name (str): The new name for the worksheet.
|
|
209
|
+
|
|
210
|
+
Examples:
|
|
211
|
+
>>> ws.rename("NewSheetName")
|
|
212
|
+
"""
|
|
213
|
+
self._name = new_name
|
|
214
|
+
|
|
215
|
+
@property
|
|
216
|
+
def cells(self):
|
|
217
|
+
"""
|
|
218
|
+
Gets the Cells collection for this worksheet.
|
|
219
|
+
|
|
220
|
+
Returns:
|
|
221
|
+
Cells: The Cells collection containing all cells in the worksheet.
|
|
222
|
+
"""
|
|
223
|
+
return self._cells
|
|
224
|
+
|
|
225
|
+
@property
|
|
226
|
+
def visible(self):
|
|
227
|
+
"""
|
|
228
|
+
Gets or sets the visibility state of the worksheet.
|
|
229
|
+
|
|
230
|
+
Returns:
|
|
231
|
+
bool or str: True for visible, False for hidden, 'veryHidden' for very hidden.
|
|
232
|
+
"""
|
|
233
|
+
return self._visible
|
|
234
|
+
|
|
235
|
+
@visible.setter
|
|
236
|
+
def visible(self, value):
|
|
237
|
+
"""
|
|
238
|
+
Sets the visibility state of the worksheet.
|
|
239
|
+
|
|
240
|
+
Args:
|
|
241
|
+
value (bool or str): True for visible, False for hidden, 'veryHidden' for very hidden.
|
|
242
|
+
"""
|
|
243
|
+
self._visible = value
|
|
244
|
+
|
|
245
|
+
@property
|
|
246
|
+
def tab_color(self):
|
|
247
|
+
"""
|
|
248
|
+
Gets or sets the tab color of the worksheet.
|
|
249
|
+
|
|
250
|
+
Returns:
|
|
251
|
+
str: The tab color in RGB hex format (AARRGGBB), or None if not set.
|
|
252
|
+
"""
|
|
253
|
+
return self._tab_color
|
|
254
|
+
|
|
255
|
+
@tab_color.setter
|
|
256
|
+
def tab_color(self, value):
|
|
257
|
+
"""
|
|
258
|
+
Sets the tab color of the worksheet.
|
|
259
|
+
|
|
260
|
+
Args:
|
|
261
|
+
value (str): The tab color in RGB hex format (AARRGGBB), or None to clear.
|
|
262
|
+
"""
|
|
263
|
+
self._tab_color = value
|
|
264
|
+
|
|
265
|
+
@property
|
|
266
|
+
def auto_filter(self):
|
|
267
|
+
"""
|
|
268
|
+
Gets the AutoFilter object for this worksheet.
|
|
269
|
+
|
|
270
|
+
Returns:
|
|
271
|
+
AutoFilter: The AutoFilter object.
|
|
272
|
+
"""
|
|
273
|
+
return self._auto_filter
|
|
274
|
+
|
|
275
|
+
@property
|
|
276
|
+
def conditional_formats(self):
|
|
277
|
+
"""
|
|
278
|
+
Gets the collection of conditional formats for this worksheet.
|
|
279
|
+
|
|
280
|
+
Returns:
|
|
281
|
+
ConditionalFormatCollection: The collection of conditional formats.
|
|
282
|
+
"""
|
|
283
|
+
return self._conditional_formats
|
|
284
|
+
|
|
285
|
+
@property
|
|
286
|
+
def data_validations(self):
|
|
287
|
+
"""
|
|
288
|
+
Gets the collection of data validations for this worksheet.
|
|
289
|
+
|
|
290
|
+
Data validation allows you to control what data can be entered into cells.
|
|
291
|
+
You can create rules to restrict data entry to specific types, values,
|
|
292
|
+
or ranges, and display messages or errors when invalid data is entered.
|
|
293
|
+
|
|
294
|
+
Returns:
|
|
295
|
+
DataValidationCollection: The collection of data validations.
|
|
296
|
+
|
|
297
|
+
Examples:
|
|
298
|
+
>>> from aspose_cells import Workbook
|
|
299
|
+
>>> from aspose_cells.data_validation import DataValidationType, DataValidationOperator
|
|
300
|
+
>>>
|
|
301
|
+
>>> wb = Workbook()
|
|
302
|
+
>>> ws = wb.worksheets[0]
|
|
303
|
+
>>>
|
|
304
|
+
>>> # Add a whole number validation
|
|
305
|
+
>>> dv = ws.data_validations.add("A1:A10")
|
|
306
|
+
>>> dv.type = DataValidationType.WHOLE_NUMBER
|
|
307
|
+
>>> dv.operator = DataValidationOperator.BETWEEN
|
|
308
|
+
>>> dv.formula1 = "1"
|
|
309
|
+
>>> dv.formula2 = "100"
|
|
310
|
+
>>> dv.show_error_message = True
|
|
311
|
+
>>> dv.error_message = "Please enter a number between 1 and 100"
|
|
312
|
+
>>>
|
|
313
|
+
>>> # Add a dropdown list validation
|
|
314
|
+
>>> dv2 = ws.data_validations.add("B1:B10")
|
|
315
|
+
>>> dv2.type = DataValidationType.LIST
|
|
316
|
+
>>> dv2.formula1 = '"Red,Green,Blue"'
|
|
317
|
+
>>> dv2.show_dropdown = True
|
|
318
|
+
"""
|
|
319
|
+
return self._data_validations
|
|
320
|
+
|
|
321
|
+
@property
|
|
322
|
+
def hyperlinks(self):
|
|
323
|
+
"""
|
|
324
|
+
Gets the collection of hyperlinks for this worksheet.
|
|
325
|
+
|
|
326
|
+
Returns:
|
|
327
|
+
Hyperlinks: The collection of hyperlinks.
|
|
328
|
+
|
|
329
|
+
Examples:
|
|
330
|
+
>>> # Add external hyperlink
|
|
331
|
+
>>> link = ws.hyperlinks.add("A1", "https://www.example.com")
|
|
332
|
+
>>> link.text_to_display = "Visit Website"
|
|
333
|
+
|
|
334
|
+
>>> # Add internal hyperlink
|
|
335
|
+
>>> link = ws.hyperlinks.add("B2", sub_address="Sheet2!A1")
|
|
336
|
+
>>> link.text_to_display = "Go to Sheet2"
|
|
337
|
+
"""
|
|
338
|
+
return self._hyperlinks
|
|
339
|
+
|
|
340
|
+
@property
|
|
341
|
+
def protection(self):
|
|
342
|
+
"""
|
|
343
|
+
Gets the protection settings for this worksheet.
|
|
344
|
+
|
|
345
|
+
Returns:
|
|
346
|
+
SheetProtectionDictWrapper: Dictionary-like object containing protection settings.
|
|
347
|
+
"""
|
|
348
|
+
return SheetProtectionDictWrapper(self._properties.protection)
|
|
349
|
+
|
|
350
|
+
@property
|
|
351
|
+
def page_setup(self):
|
|
352
|
+
"""
|
|
353
|
+
Gets the page setup settings for this worksheet.
|
|
354
|
+
|
|
355
|
+
Returns:
|
|
356
|
+
dict: Dictionary containing page setup settings.
|
|
357
|
+
"""
|
|
358
|
+
return self._page_setup
|
|
359
|
+
|
|
360
|
+
@property
|
|
361
|
+
def page_margins(self):
|
|
362
|
+
"""
|
|
363
|
+
Gets the page margins for this worksheet.
|
|
364
|
+
|
|
365
|
+
Returns:
|
|
366
|
+
dict: Dictionary containing page margin settings (in inches).
|
|
367
|
+
"""
|
|
368
|
+
return self._page_margins
|
|
369
|
+
|
|
370
|
+
@property
|
|
371
|
+
def properties(self):
|
|
372
|
+
"""
|
|
373
|
+
Gets the worksheet properties.
|
|
374
|
+
|
|
375
|
+
Returns:
|
|
376
|
+
WorksheetProperties: The worksheet properties object containing
|
|
377
|
+
view, selection, pane, format, protection, page setup, margins,
|
|
378
|
+
header/footer, and print options.
|
|
379
|
+
|
|
380
|
+
Examples:
|
|
381
|
+
>>> ws.properties.view.show_grid_lines = False
|
|
382
|
+
>>> ws.properties.view.zoom_scale = 80
|
|
383
|
+
>>> ws.properties.page_setup.orientation = "landscape"
|
|
384
|
+
"""
|
|
385
|
+
return self._properties
|
|
386
|
+
|
|
387
|
+
# Methods
|
|
388
|
+
|
|
389
|
+
def is_protected(self):
|
|
390
|
+
"""
|
|
391
|
+
Checks if the worksheet is protected.
|
|
392
|
+
|
|
393
|
+
Returns:
|
|
394
|
+
bool: True if the worksheet is protected, False otherwise.
|
|
395
|
+
"""
|
|
396
|
+
return self._properties.protection.sheet
|
|
397
|
+
|
|
398
|
+
def protect(self, password=None, format_cells=None, format_columns=None, format_rows=None,
|
|
399
|
+
insert_columns=None, insert_rows=None, delete_columns=None, delete_rows=None,
|
|
400
|
+
sort=None, auto_filter=None, insert_hyperlinks=None, pivot_tables=None,
|
|
401
|
+
select_locked_cells=None, select_unlocked_cells=None, objects=None, scenarios=None):
|
|
402
|
+
"""
|
|
403
|
+
Protects the worksheet with optional password and protection options.
|
|
404
|
+
|
|
405
|
+
Args:
|
|
406
|
+
password (str, optional): Password for worksheet protection. Defaults to None.
|
|
407
|
+
format_cells (bool, optional): Allow formatting cells. Defaults to None (keeps current).
|
|
408
|
+
format_columns (bool, optional): Allow formatting columns. Defaults to None (keeps current).
|
|
409
|
+
format_rows (bool, optional): Allow formatting rows. Defaults to None (keeps current).
|
|
410
|
+
insert_columns (bool, optional): Allow inserting columns. Defaults to None (keeps current).
|
|
411
|
+
insert_rows (bool, optional): Allow inserting rows. Defaults to None (keeps current).
|
|
412
|
+
delete_columns (bool, optional): Allow deleting columns. Defaults to None (keeps current).
|
|
413
|
+
delete_rows (bool, optional): Allow deleting rows. Defaults to None (keeps current).
|
|
414
|
+
sort (bool, optional): Allow sorting. Defaults to None (keeps current).
|
|
415
|
+
auto_filter (bool, optional): Allow auto filter. Defaults to None (keeps current).
|
|
416
|
+
insert_hyperlinks (bool, optional): Allow inserting hyperlinks. Defaults to None (keeps current).
|
|
417
|
+
pivot_tables (bool, optional): Allow pivot tables. Defaults to None (keeps current).
|
|
418
|
+
select_locked_cells (bool, optional): Allow selecting locked cells. Defaults to None (keeps current).
|
|
419
|
+
select_unlocked_cells (bool, optional): Allow selecting unlocked cells. Defaults to None (keeps current).
|
|
420
|
+
objects (bool, optional): Protect objects. Defaults to None (keeps current).
|
|
421
|
+
scenarios (bool, optional): Protect scenarios. Defaults to None (keeps current).
|
|
422
|
+
|
|
423
|
+
Examples:
|
|
424
|
+
>>> ws.protect() # Protect without password
|
|
425
|
+
>>> ws.protect("mypassword") # Protect with password
|
|
426
|
+
>>> ws.protect("secure", format_cells=True, sort=False) # Protect with options
|
|
427
|
+
"""
|
|
428
|
+
# Enable sheet protection
|
|
429
|
+
self._properties.protection.sheet = True
|
|
430
|
+
|
|
431
|
+
# Set password (will be hashed when saving to XML)
|
|
432
|
+
if password is not None:
|
|
433
|
+
self._properties.protection.password = password
|
|
434
|
+
|
|
435
|
+
# Set protection options if provided
|
|
436
|
+
if format_cells is not None:
|
|
437
|
+
self._properties.protection.format_cells = format_cells
|
|
438
|
+
if format_columns is not None:
|
|
439
|
+
self._properties.protection.format_columns = format_columns
|
|
440
|
+
if format_rows is not None:
|
|
441
|
+
self._properties.protection.format_rows = format_rows
|
|
442
|
+
if insert_columns is not None:
|
|
443
|
+
self._properties.protection.insert_columns = insert_columns
|
|
444
|
+
if insert_rows is not None:
|
|
445
|
+
self._properties.protection.insert_rows = insert_rows
|
|
446
|
+
if delete_columns is not None:
|
|
447
|
+
self._properties.protection.delete_columns = delete_columns
|
|
448
|
+
if delete_rows is not None:
|
|
449
|
+
self._properties.protection.delete_rows = delete_rows
|
|
450
|
+
if sort is not None:
|
|
451
|
+
self._properties.protection.sort = sort
|
|
452
|
+
if auto_filter is not None:
|
|
453
|
+
self._properties.protection.auto_filter = auto_filter
|
|
454
|
+
if insert_hyperlinks is not None:
|
|
455
|
+
self._properties.protection.insert_hyperlinks = insert_hyperlinks
|
|
456
|
+
if pivot_tables is not None:
|
|
457
|
+
self._properties.protection.pivot_tables = pivot_tables
|
|
458
|
+
if select_locked_cells is not None:
|
|
459
|
+
self._properties.protection.select_locked_cells = select_locked_cells
|
|
460
|
+
if select_unlocked_cells is not None:
|
|
461
|
+
self._properties.protection.select_unlocked_cells = select_unlocked_cells
|
|
462
|
+
if objects is not None:
|
|
463
|
+
self._properties.protection.objects = objects
|
|
464
|
+
if scenarios is not None:
|
|
465
|
+
self._properties.protection.scenarios = scenarios
|
|
466
|
+
|
|
467
|
+
def unprotect(self, password=None):
|
|
468
|
+
"""
|
|
469
|
+
Unprotects the worksheet.
|
|
470
|
+
|
|
471
|
+
Args:
|
|
472
|
+
password (str, optional): Password to unprotect the worksheet. Defaults to None.
|
|
473
|
+
Note: Password validation is not currently implemented.
|
|
474
|
+
|
|
475
|
+
Examples:
|
|
476
|
+
>>> ws.unprotect() # Unprotect without password
|
|
477
|
+
>>> ws.unprotect("mypassword") # Unprotect with password
|
|
478
|
+
"""
|
|
479
|
+
# Note: We don't validate the password here - just disable protection
|
|
480
|
+
# In a full implementation, we would check if the password matches
|
|
481
|
+
self._properties.protection.sheet = False
|
|
482
|
+
self._properties.protection.password = None
|
|
483
|
+
|
|
484
|
+
def set_view(self, zoom=None, show_grid_lines=None, show_row_col_headers=None):
|
|
485
|
+
"""
|
|
486
|
+
Sets view options for the worksheet.
|
|
487
|
+
|
|
488
|
+
Args:
|
|
489
|
+
zoom (int, optional): Zoom percentage (10-400). Defaults to None.
|
|
490
|
+
show_grid_lines (bool, optional): Whether to show grid lines. Defaults to None.
|
|
491
|
+
show_row_col_headers (bool, optional): Whether to show row and column headers. Defaults to None.
|
|
492
|
+
"""
|
|
493
|
+
# This is a placeholder for future implementation
|
|
494
|
+
pass
|
|
495
|
+
|
|
496
|
+
def copy(self, name=None):
|
|
497
|
+
"""
|
|
498
|
+
Creates a copy of the worksheet.
|
|
499
|
+
|
|
500
|
+
Args:
|
|
501
|
+
name (str, optional): Name for the copied worksheet. If None, a default name is generated.
|
|
502
|
+
|
|
503
|
+
Returns:
|
|
504
|
+
Worksheet: The copied worksheet.
|
|
505
|
+
"""
|
|
506
|
+
new_ws = Worksheet(name if name else f"{self._name} (copy)")
|
|
507
|
+
# Copy cells
|
|
508
|
+
for ref, cell in self._cells._cells.items():
|
|
509
|
+
new_ws._cells._cells[ref] = Cell(cell.value, cell.formula)
|
|
510
|
+
if cell.style:
|
|
511
|
+
new_ws._cells._cells[ref].style = cell.style.copy()
|
|
512
|
+
return new_ws
|
|
513
|
+
|
|
514
|
+
def delete(self):
|
|
515
|
+
"""
|
|
516
|
+
Deletes the worksheet from the workbook.
|
|
517
|
+
|
|
518
|
+
Note: This method is a placeholder. The actual deletion is handled by the Workbook class.
|
|
519
|
+
"""
|
|
520
|
+
pass
|
|
521
|
+
|
|
522
|
+
def move(self, index):
|
|
523
|
+
"""
|
|
524
|
+
Moves the worksheet to the specified position in the workbook.
|
|
525
|
+
|
|
526
|
+
Args:
|
|
527
|
+
index (int): Zero-based index where to move the worksheet.
|
|
528
|
+
|
|
529
|
+
Note: This method is a placeholder. The actual move is handled by the Workbook class.
|
|
530
|
+
"""
|
|
531
|
+
pass
|
|
532
|
+
|
|
533
|
+
def select(self):
|
|
534
|
+
"""
|
|
535
|
+
Selects the worksheet.
|
|
536
|
+
|
|
537
|
+
Note: This method is a placeholder. The actual selection is handled by the Workbook class.
|
|
538
|
+
"""
|
|
539
|
+
pass
|
|
540
|
+
|
|
541
|
+
def activate(self):
|
|
542
|
+
"""
|
|
543
|
+
Activates the worksheet (makes it the active worksheet).
|
|
544
|
+
|
|
545
|
+
Note: This method is a placeholder. The actual activation is handled by the Workbook class.
|
|
546
|
+
"""
|
|
547
|
+
pass
|
|
548
|
+
|
|
549
|
+
def calculate_formula(self):
|
|
550
|
+
"""
|
|
551
|
+
Calculates formulas in the worksheet.
|
|
552
|
+
|
|
553
|
+
Note: This method is a placeholder for future implementation.
|
|
554
|
+
"""
|
|
555
|
+
pass
|
|
556
|
+
|
|
557
|
+
def get_range(self, start_cell, end_cell=None):
|
|
558
|
+
"""
|
|
559
|
+
Gets a range of cells.
|
|
560
|
+
|
|
561
|
+
Args:
|
|
562
|
+
start_cell (str): The starting cell reference (e.g., "A1").
|
|
563
|
+
end_cell (str, optional): The ending cell reference. If None, returns a single cell.
|
|
564
|
+
|
|
565
|
+
Returns:
|
|
566
|
+
The range or cell.
|
|
567
|
+
|
|
568
|
+
Note: This method is a placeholder for future implementation.
|
|
569
|
+
"""
|
|
570
|
+
pass
|