本文整理汇总了Python中openpyxl.cell.Cell.alignment方法的典型用法代码示例。如果您正苦于以下问题:Python Cell.alignment方法的具体用法?Python Cell.alignment怎么用?Python Cell.alignment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类openpyxl.cell.Cell
的用法示例。
在下文中一共展示了Cell.alignment方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: put_text
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import alignment [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
示例2: print_sales_content
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import alignment [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])
示例3: process_xls
# 需要导入模块: from openpyxl.cell import Cell [as 别名]
# 或者: from openpyxl.cell.Cell import alignment [as 别名]
def process_xls(data, config=None):
header = data['header']
title = header['title']
origin = data['dataOrigin']
book = Workbook()
sheet = book.active
doc_id = unique_id()
files_path = config.get('files', 'path')
if 'logoURL' in header:
try:
response = requests.get(header['logoURL'], stream=True)
logo = Image(response.raw)
logo = Image(logo.image.resize((100, 100)))
except requests.ConnectionError as cerror:
print(cerror, file=sys.stderr)
else:
logo = None
hdr_bkg_color = header['backgroundColor']
header_bkg = PatternFill(fill_type="solid",
start_color=hdr_bkg_color,
end_color=hdr_bkg_color)
colformats = []
coltypes = []
has_formats = False
columns = data.get('columns', [])
try:
for col in columns:
colfmt = col.get('format', None)
coltype = col.get('type', None)
colformats.append(colfmt)
coltypes.append(coltype)
has_formats = True
except TypeError:
pass
if origin == 'array':
rows = data['rows']
cell = Cell(sheet, value=title)
cell.alignment = Alignment(horizontal='center',
vertical='center')
sheet.append(['', '', '', cell])
sheet.merge_cells('A1:C1')
sheet.merge_cells('D1:G1')
for row in rows:
cells = []
for value in row:
cell = Cell(sheet, value=value)
cells.append(cell)
sheet.append(cells)
else:
db = data['database']
sql_query = data['sqlQuery']
url_callback = data['urlCallback']
title = data['title']
columns = data['columns']
"""
conn = pg_connect(host=db['host'],
database=db['name'],
password=db['password'],
user=db['user'])
cursor = conn.cursor()
cursor.execute(sql_query)
"""
index = 0
is_first = True
for row in cursor:
if is_first:
sheet.merge_cells('A1:C1')
sheet.merge_cells('D1:G1')
sheet.append(['', '', '', cell])
if logo:
sheet.add_image(logo, 'A1')
headcells = []
for col in columns:
cell = Cell(sheet, value=col['label'])
cell.fill = header_bkg
coltype = col.get('type', None)
colfmt = col.get('format', None)
columns_format.append(colfmt)
columns_type.append(coltype)
#.........这里部分代码省略.........