markup/spreadsheet.py: add category + size, add styling
This commit is contained in:
@ -15,16 +15,40 @@ def format_season(s):
|
||||
return s[:1] + s[2:]
|
||||
|
||||
|
||||
def format_name(name, gender):
|
||||
return '{}-{}'.format(name, gender[:1])
|
||||
|
||||
|
||||
def write_spreadsheet(matches, workdir, file_base):
|
||||
if not matches:
|
||||
print('write_spreadsheet: no matches. skipping.')
|
||||
return None
|
||||
|
||||
header_font = Font(name='Calibri', size=12, bold=True)
|
||||
body_font = Font(name='Calibri', size=12)
|
||||
header_fill = PatternFill(start_color="cccccc", end_color="cccccc", fill_type="solid")
|
||||
body_fill = PatternFill(start_color="eeeeee", end_color="eeeeee", fill_type="solid")
|
||||
thin_side = Side(border_style='thin', color='000000')
|
||||
border = Border(bottom=thin_side)
|
||||
|
||||
wb = Workbook()
|
||||
ws = wb.active
|
||||
|
||||
# header row
|
||||
ws.append(['Season', 'Gender', 'Name', 'Style Number', 'Color'])
|
||||
ws.append(['Style Number', 'Product Name', 'Season', 'Color', 'Category', 'Size Range'])
|
||||
|
||||
# style the header row
|
||||
ws.column_dimensions['A'].width = 15
|
||||
ws.column_dimensions['B'].width = 30
|
||||
ws.column_dimensions['C'].width = 10
|
||||
ws.column_dimensions['D'].width = 30
|
||||
ws.column_dimensions['E'].width = 15
|
||||
ws.column_dimensions['F'].width = 35
|
||||
|
||||
for f in ('A1', 'B1', 'C1', 'D1', 'E1', 'F1'):
|
||||
ws[f].font = header_font
|
||||
ws[f].fill = header_fill
|
||||
ws[f].border = border
|
||||
|
||||
# TODO: sort matches
|
||||
|
||||
@ -33,17 +57,26 @@ def write_spreadsheet(matches, workdir, file_base):
|
||||
for m in matches:
|
||||
# in the case of kids,
|
||||
# we might have multiple products in a match
|
||||
seasons = m['season'].split('\n')
|
||||
genders = m['gender'].split('\n')
|
||||
names = m['name'].split('\n')
|
||||
materials = m['material'].split('\n')
|
||||
colors = m['color'].split('\n')
|
||||
seasons = m['season'].split('\n')
|
||||
genders = m['gender'].split('\n')
|
||||
names = m['name'].split('\n')
|
||||
materials = m['material'].split('\n')
|
||||
colors = m['color'].split('\n')
|
||||
sizes = m['size'].split('\n')
|
||||
categories = m['category'].split('\n')
|
||||
|
||||
for s, g, n, m, c in zip_longest(seasons, genders, names, materials, colors, fillvalue=''):
|
||||
for s, g, n, m, c, sz, ct in zip_longest(seasons, genders, names, materials, colors, sizes, categories, fillvalue=''):
|
||||
if not m in seen:
|
||||
ws.append([format_season(s), g, n, m, c])
|
||||
ws.append([m, format_name(n, g), format_season(s), c, ct, sz])
|
||||
seen[m] = True
|
||||
|
||||
# style body
|
||||
for row in ws.iter_rows(min_row=2, max_row=None, max_col=None):
|
||||
for cell in row:
|
||||
cell.font = body_font
|
||||
cell.fill = body_fill
|
||||
cell.border = border
|
||||
|
||||
# save
|
||||
ensure_dir(workdir)
|
||||
path = os.path.join(workdir, f"{file_base}.xlsx")
|
||||
|
||||
Reference in New Issue
Block a user