本文整理汇总了Python中openpyxl.cell.Cell.style方法的典型用法代码示例。如果您正苦于以下问题:Python Cell.style方法的具体用法?Python Cell.style怎么用?Python Cell.style使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openpyxl.cell.Cell
的用法示例。
在下文中一共展示了Cell.style方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_is_not_date_color_format
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import style [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='0.00_);[Red]\(0.00\)')
assert cell.is_date() is False
示例2: setStyle
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import style [as 别名]
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
示例3: print_sales_content
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import style [as 别名]
def print_sales_content(collection, ws):
# Table Header
table_headers = ['Date', 'O.R. #', 'Name', 'Amount', 'Remarks']
table_header_cells = []
for h in table_headers:
c = underline_border_cell(h, ws)
table_header_cells.append(c)
r = [''] + table_header_cells
ws.append(r)
sales_total = 0
for item in collection:
if item.label == 'Cemetery Lot':
amount = item.lot_area * item.price_per_sq_mtr
# elif item.label == 'Cremation': # todo no amount for cremation yet
# amount = 0
elif item.label == 'Columbary':
amount = item.price if item.price is not None else 0
amount_formatted = 'P {:20,.2f}'.format(amount)
amount_formatted_cell = Cell(ws, value=amount_formatted)
amount_formatted_cell.style = Style(alignment=Alignment(horizontal='right'))
client_name = item.client.get_full_name() if item.client is not None else ''
sales_total += amount
ws.append(['', item.date_purchased, item.or_no, client_name, amount_formatted_cell, item.label])
# Sales Total
total_label_cell = Cell(ws, value='TOTAL')
total_label_cell.font = Font(size=12, color='FFFF0000')
total_cell = Cell(ws, value='P {:20,.2f}'.format(sales_total))
total_cell.font = Font(size=12, color='FFFF0000')
total_cell.border = total_border
total_cell.alignment = Alignment(horizontal='right')
ws.append(['', '', '', total_label_cell, total_cell])
示例4: set_col_widths
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import style [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[:] = ()