本文整理汇总了Python中openpyxl.cell.Cell类的典型用法代码示例。如果您正苦于以下问题:Python Cell类的具体用法?Python Cell怎么用?Python Cell使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cell类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_time
def test_time(value, expected):
wb = Workbook(guess_types=True)
ws = Worksheet(wb)
cell = Cell(ws, 'A', 1)
cell.value = value
assert cell.value == expected
assert cell.TYPE_NUMERIC == cell.data_type
示例2: test_date_format_on_non_date
def test_date_format_on_non_date():
wb = Workbook()
ws = Worksheet(wb)
cell = Cell(ws, "A", 1)
cell.value = datetime.now()
cell.value = "testme"
eq_("testme", cell.value)
示例3: parse_cell
def parse_cell(self, element):
value = element.find(self.VALUE_TAG)
if value is not None:
value = value.text
formula = element.find(self.FORMULA_TAG)
data_type = element.get('t', 'n')
coordinate = element.get('r')
style_id = element.get('s')
# assign formula to cell value unless only the data is desired
if formula is not None and not self.data_only:
data_type = 'f'
if formula.text:
value = "=" + formula.text
else:
value = "="
formula_type = formula.get('t')
if formula_type:
self.ws.formula_attributes[coordinate] = {'t': formula_type}
si = formula.get('si') # Shared group index for shared formulas
if si:
self.ws.formula_attributes[coordinate]['si'] = si
ref = formula.get('ref') # Range for shared formulas
if ref:
self.ws.formula_attributes[coordinate]['ref'] = ref
style = {}
if style_id is not None:
style_id = int(style_id)
style = self.styles[style_id]
column, row = coordinate_from_string(coordinate)
cell = Cell(self.ws, column, row, **style)
self.ws._add_cell(cell)
if value is not None:
if data_type == 'n':
value = cell._cast_numeric(value)
elif data_type == 'b':
value = bool(int(value))
elif data_type == 's':
value = self.shared_strings[int(value)]
elif data_type == 'str':
data_type = 's'
else:
if data_type == 'inlineStr':
data_type = 's'
child = element.find(self.INLINE_STRING)
if child is None:
child = element.find(self.INLINE_RICHTEXT)
if child is not None:
value = child.text
if self.guess_types or value is None:
cell.value = value
else:
cell._value=value
cell.data_type=data_type
示例4: underline_border_cell
def underline_border_cell(val, ws):
underline_border = Border(bottom=Side(style='thin'))
c = Cell(ws, value=val)
c.font = Font(size=11, bold=True)
c.border = underline_border
return c
示例5: test_number_format
def test_number_format(DummyWorksheet, Cell):
ws = DummyWorksheet
ws.parent._number_formats.add("dd--hh--mm")
cell = Cell(ws, column="A", row=1)
cell.number_format = "dd--hh--mm"
assert cell.number_format == "dd--hh--mm"
示例6: test_timedelta
def test_timedelta():
wb = Workbook()
ws = Worksheet(wb)
cell = Cell(ws, 'A', 1)
cell.value = timedelta(days=1, hours=3)
assert cell.value == 1.125
assert cell.TYPE_NUMERIC == cell.data_type
示例7: put_text
def put_text(cell: Cell, text, font=None, border=None, alignment=None):
cell.value = text
if font:
cell.font = font
if border:
cell.border = border
if alignment:
cell.alignment = alignment
return cell
示例8: test_is_date
def test_is_date():
wb = Workbook()
ws = Worksheet(wb)
cell = Cell(ws, 'A', 1)
cell.value = datetime.now()
assert cell.is_date() == True
cell.value = 'testme'
assert 'testme' == cell.value
assert cell.is_date() is False
示例9: test_is_date
def test_is_date():
wb = Workbook()
ws = Worksheet(wb)
cell = Cell(ws, "A", 1)
cell.value = datetime.now()
eq_(cell.is_date(), True)
cell.value = "testme"
eq_("testme", cell.value)
eq_(cell.is_date(), False)
示例10: test_is_not_date_color_format
def test_is_not_date_color_format():
wb = Workbook()
ws = Worksheet(wb)
cell = Cell(ws, 'A', 1)
cell.value = -13.5
cell.style = cell.style.copy(number_format=NumberFormat('0.00_);[Red]\(0.00\)'))
assert cell.is_date() is False
示例11: test_is_not_date_color_format
def test_is_not_date_color_format():
wb = Workbook()
ws = Worksheet(wb)
cell = Cell(ws, "A", 1)
cell.value = -13.5
cell.style.number_format.format_code = "0.00_);[Red]\(0.00\)"
eq_(cell.is_date(), False)
示例12: setStyle
def setStyle(ws, value, style):
# Silence the warning about using a composite Style object instead of Font.
with warnings.catch_warnings():
warnings.simplefilter("ignore", UserWarning)
try:
result = [Cell(ws, column='A', row = 1, value=item) for item in value]
for cell in result:
cell.style = style
except TypeError:
result = Cell(ws, column='A', row = 1, value=value)
result.style = style
return result
示例13: test_data_type_check
def test_data_type_check():
cell = Cell(None, 'A', 1)
cell.bind_value(None)
eq_(Cell.TYPE_NULL, cell._data_type)
cell.bind_value('.0e000')
eq_(Cell.TYPE_NUMERIC, cell._data_type)
cell.bind_value('-0.e-0')
eq_(Cell.TYPE_NUMERIC, cell._data_type)
cell.bind_value('1E')
eq_(Cell.TYPE_STRING, cell._data_type)
示例14: test_data_type_check
def test_data_type_check():
ws = build_dummy_worksheet()
cell = Cell(ws, "A", 1)
cell.bind_value(None)
eq_(Cell.TYPE_NULL, cell._data_type)
cell.bind_value(".0e000")
eq_(Cell.TYPE_NUMERIC, cell._data_type)
cell.bind_value("-0.e-0")
eq_(Cell.TYPE_NUMERIC, cell._data_type)
cell.bind_value("1E")
eq_(Cell.TYPE_STRING, cell._data_type)
示例15: test_data_type_check
def test_data_type_check():
class Ws(object):
encoding = 'utf-8'
cell = Cell(Ws(), 'A', 1)
cell.bind_value(None)
eq_(Cell.TYPE_NULL, cell._data_type)
cell.bind_value('.0e000')
eq_(Cell.TYPE_NUMERIC, cell._data_type)
cell.bind_value('-0.e-0')
eq_(Cell.TYPE_NUMERIC, cell._data_type)
cell.bind_value('1E')
eq_(Cell.TYPE_STRING, cell._data_type)