Coverage for /home/martinb/.local/share/virtualenvs/camcops/lib/python3.6/site-packages/openpyxl/cell/read_only.py : 49%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Copyright (c) 2010-2020 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]
58 @property
59 def number_format(self):
60 _id = self.style_array.numFmtId
61 if _id < BUILTIN_FORMATS_MAX_SIZE:
62 return BUILTIN_FORMATS.get(_id, "General")
63 else:
64 return self.parent.parent._number_formats[
65 _id - BUILTIN_FORMATS_MAX_SIZE]
67 @property
68 def font(self):
69 _id = self.style_array.fontId
70 return self.parent.parent._fonts[_id]
72 @property
73 def fill(self):
74 _id = self.style_array.fillId
75 return self.parent.parent._fills[_id]
77 @property
78 def border(self):
79 _id = self.style_array.borderId
80 return self.parent.parent._borders[_id]
82 @property
83 def alignment(self):
84 _id = self.style_array.alignmentId
85 return self.parent.parent._alignments[_id]
87 @property
88 def protection(self):
89 _id = self.style_array.protectionId
90 return self.parent.parent._protections[_id]
93 @property
94 def is_date(self):
95 return Cell.is_date.__get__(self)
98 @property
99 def internal_value(self):
100 return self._value
102 @property
103 def value(self):
104 return self._value
106 @value.setter
107 def value(self, value):
108 if self._value is not None:
109 raise AttributeError("Cell is read only")
110 self._value = value
113class EmptyCell(object):
115 __slots__ = ()
117 value = None
118 is_date = False
119 font = None
120 border = None
121 fill = None
122 number_format = None
123 alignment = None
124 data_type = 'n'
127 def __repr__(self):
128 return "<EmptyCell>"
130EMPTY_CELL = EmptyCell()