本文整理汇总了Python中openpyxl.cell.Cell.value方法的典型用法代码示例。如果您正苦于以下问题:Python Cell.value方法的具体用法?Python Cell.value怎么用?Python Cell.value使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openpyxl.cell.Cell
的用法示例。
在下文中一共展示了Cell.value方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_date_format_on_non_date
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import value [as 别名]
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)
示例2: test_is_date
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import value [as 别名]
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
示例3: test_is_date
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import value [as 别名]
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)
示例4: test_time
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import value [as 别名]
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
示例5: parse_cell
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import value [as 别名]
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
示例6: test_timedelta
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import value [as 别名]
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
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import value [as 别名]
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_not_date_color_format
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import value [as 别名]
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)
示例9: test_is_not_date_color_format
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import value [as 别名]
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
示例10: set_col_widths
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import value [as 别名]
def set_col_widths(self):
from openpyxl.utils.cell import get_column_letter
from openpyxl.cell import Cell
TYPE_STRING = Cell.TYPE_STRING
for idx, width in sorted(self._col_widths.iteritems()):
letter = get_column_letter(idx + 1)
self.sheet.column_dimensions[letter].width = 1 + min(width, 50)
for row in self._rows:
values = []
for val in row:
if val:
value = val.value
cell = Cell(self.sheet, column='A', row=1)
if isinstance(value, basestring):
cell.set_explicit_value(value, data_type=TYPE_STRING)
else:
cell.value = value
cell.style = val.style
else:
cell = val
values.append(cell)
self.sheet.append(values)
self._rows[:] = ()
示例11: test_illegal_chacters
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import value [as 别名]
def test_illegal_chacters():
from openpyxl.exceptions import IllegalCharacterError
from openpyxl.compat import range
from itertools import chain
ws = build_dummy_worksheet()
cell = Cell(ws, 'A', 1)
# The bytes 0x00 through 0x1F inclusive must be manually escaped in values.
illegal_chrs = chain(range(9), range(11, 13), range(14, 32))
for i in illegal_chrs:
with pytest.raises(IllegalCharacterError):
cell.value = chr(i)
with pytest.raises(IllegalCharacterError):
cell.value = "A {0} B".format(chr(i))
cell.value = chr(33)
cell.value = chr(9) # Tab
cell.value = chr(10) # Newline
cell.value = chr(13) # Carriage return
cell.value = " Leading and trailing spaces are legal "
示例12: parse_cell
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import value [as 别名]
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
if formula_type == "shared":
# The spec (18.3.1.40) defines shared formulae in
# terms of the following:
#
# `master`: "The first formula in a group of shared
# formulas"
# `ref`: "Range of cells which the formula applies
# to." It's a required attribute on the master
# cell, forbidden otherwise.
# `shared cell`: "A cell is shared only when si is
# used and t is `shared`."
#
# Whether to use the cell's given formula or the
# master's depends on whether the cell is shared,
# whether it's in the ref, and whether it defines its
# own formula, as follows:
#
# Shared? Has formula? | In ref Not in ref
# ========= ==============|======== ===============
# Yes Yes | master impl. defined
# No Yes | own own
# Yes No | master impl. defined
# No No | ?? N/A
#
# The ?? is because the spec is silent on this issue,
# though my inference is that the cell does not
# receive a formula at all.
#
# For this implementation, we are using the master
# formula in the two "impl. defined" cases and no
# formula in the "??" case. This choice of
# implementation allows us to disregard the `ref`
# parameter altogether, and does not require
# computing expressions like `C5 in A1:D6`.
# Presumably, Excel does not generate spreadsheets
# with such contradictions.
try:
trans = self.shared_formula_masters[si]
except KeyError:
# This cell must be master
self.shared_formula_masters[si] = Translator(
value, coordinate)
else:
value = trans.translate_formula(coordinate)
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]
row, column = coordinate_to_tuple(coordinate)
cell = Cell(self.ws, row=row, col_idx=column, **style)
self.ws._cells[(row, column)] = cell
if value is not None:
if data_type == 'n':
value = _cast_number(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:
#.........这里部分代码省略.........
示例13: test_data_type_check
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import value [as 别名]
def test_data_type_check(value, datatype):
ws = build_dummy_worksheet()
ws.parent._guess_types = True
cell = Cell(ws, 'A', 1)
cell.value = value
assert cell.data_type == datatype