Coverage for /var/srv/projects/api.amasfac.comuna18.com/tmp/venv/lib/python3.9/site-packages/openpyxl/cell/read_only.py: 54%
93 statements
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
« prev ^ index » next coverage.py v6.4.4, created at 2023-07-17 14:22 -0600
1# Copyright (c) 2010-2022 openpyxl
3from openpyxl.cell import Cell
4from openpyxl.utils import get_column_letter
5from openpyxl.utils.datetime import from_excel
6from openpyxl.styles import is_date_format
7from openpyxl.styles.numbers import BUILTIN_FORMATS, BUILTIN_FORMATS_MAX_SIZE
10class ReadOnlyCell(object):
12 __slots__ = ('parent', 'row', 'column', '_value', 'data_type', '_style_id')
14 def __init__(self, sheet, row, column, value, data_type='n', style_id=0):
15 self.parent = sheet
16 self._value = None
17 self.row = row
18 self.column = column
19 self.data_type = data_type
20 self.value = value
21 self._style_id = style_id
24 def __eq__(self, other):
25 for a in self.__slots__:
26 if getattr(self, a) != getattr(other, a):
27 return
28 return True
30 def __ne__(self, other):
31 return not self.__eq__(other)
34 def __repr__(self):
35 return "<ReadOnlyCell {0!r}.{1}>".format(self.parent.title, self.coordinate)
38 @property
39 def coordinate(self):
40 column = get_column_letter(self.column)
41 return "{1}{0}".format(self.row, column)
44 @property
45 def coordinate(self):
46 return Cell.coordinate.__get__(self)
49 @property
50 def column_letter(self):
51 return Cell.column_letter.__get__(self)
54 @property
55 def style_array(self):
56 return self.parent.parent._cell_styles[self._style_id]
59 @property
60 def has_style(self):
61 return self._style_id != 0
64 @property
65 def number_format(self):
66 _id = self.style_array.numFmtId
67 if _id < BUILTIN_FORMATS_MAX_SIZE:
68 return BUILTIN_FORMATS.get(_id, "General")
69 else:
70 return self.parent.parent._number_formats[
71 _id - BUILTIN_FORMATS_MAX_SIZE]
73 @property
74 def font(self):
75 _id = self.style_array.fontId
76 return self.parent.parent._fonts[_id]
78 @property
79 def fill(self):
80 _id = self.style_array.fillId
81 return self.parent.parent._fills[_id]
83 @property
84 def border(self):
85 _id = self.style_array.borderId
86 return self.parent.parent._borders[_id]
88 @property
89 def alignment(self):
90 _id = self.style_array.alignmentId
91 return self.parent.parent._alignments[_id]
93 @property
94 def protection(self):
95 _id = self.style_array.protectionId
96 return self.parent.parent._protections[_id]
99 @property
100 def is_date(self):
101 return Cell.is_date.__get__(self)
104 @property
105 def internal_value(self):
106 return self._value
108 @property
109 def value(self):
110 return self._value
112 @value.setter
113 def value(self, value):
114 if self._value is not None:
115 raise AttributeError("Cell is read only")
116 self._value = value
119class EmptyCell(object):
121 __slots__ = ()
123 value = None
124 is_date = False
125 font = None
126 border = None
127 fill = None
128 number_format = None
129 alignment = None
130 data_type = 'n'
133 def __repr__(self):
134 return "<EmptyCell>"
136EMPTY_CELL = EmptyCell()