增加发布正式版的命令
This commit is contained in:
@@ -869,31 +869,46 @@ def generate_excel(orders, selected_fields, sum_fields, sum_results,
|
||||
charge_degree_col = col_idx
|
||||
break
|
||||
|
||||
# 第一列显示标题
|
||||
# 总列数
|
||||
total_cols = len(selected_fields) + 2
|
||||
if has_custom_service_fee:
|
||||
total_cols += 1
|
||||
|
||||
# 标题文字
|
||||
title_text = f'当月累计充电量(共{total_days}天,截止{report_date})'
|
||||
if missing_dates and len(missing_dates) > 0:
|
||||
# 最多显示5个缺失日期,超过的用"...共N天"表示
|
||||
if len(missing_dates) <= 5:
|
||||
missing_str = '、'.join([d[5:] for d in missing_dates]) # 只显示月-日
|
||||
missing_str = '、'.join([d[5:] for d in missing_dates])
|
||||
else:
|
||||
missing_str = '、'.join([d[5:] for d in missing_dates[:5]]) + f'...共{len(missing_dates)}天'
|
||||
title_text += f'\n(缺:{missing_str})'
|
||||
|
||||
ws.cell(row=monthly_row, column=1).value = title_text
|
||||
ws.cell(row=monthly_row, column=1).font = monthly_font
|
||||
ws.cell(row=monthly_row, column=1).fill = monthly_fill
|
||||
ws.cell(row=monthly_row, column=1).alignment = Alignment(horizontal='center', vertical='center', wrap_text=True)
|
||||
ws.cell(row=monthly_row, column=1).border = thin_border
|
||||
# 标题跨列:从第1列到 charge_degree_col 的前一列
|
||||
# 如果没有找到充电电量列,就跨到倒数第二列
|
||||
title_end_col = charge_degree_col - 1 if charge_degree_col else total_cols - 1
|
||||
if title_end_col < 1:
|
||||
title_end_col = 1
|
||||
|
||||
# 其他列也填充背景色
|
||||
total_cols = len(selected_fields) + 2
|
||||
if has_custom_service_fee:
|
||||
total_cols += 1
|
||||
# 合并标题单元格
|
||||
if title_end_col > 1:
|
||||
ws.merge_cells(start_row=monthly_row, start_column=1,
|
||||
end_row=monthly_row, end_column=title_end_col)
|
||||
|
||||
# 设置标题单元格
|
||||
title_cell = ws.cell(row=monthly_row, column=1)
|
||||
title_cell.value = title_text
|
||||
title_cell.font = monthly_font
|
||||
title_cell.fill = monthly_fill
|
||||
title_cell.alignment = Alignment(horizontal='center', vertical='center', wrap_text=True)
|
||||
title_cell.border = thin_border
|
||||
|
||||
# 其他列填充背景色和边框
|
||||
for col_idx in range(2, total_cols):
|
||||
cell = ws.cell(row=monthly_row, column=col_idx)
|
||||
cell.fill = monthly_fill
|
||||
cell.border = thin_border
|
||||
|
||||
# 数值放在 charge_degree 列
|
||||
if charge_degree_col:
|
||||
cell = ws.cell(row=monthly_row, column=charge_degree_col)
|
||||
cell.value = total_degree
|
||||
@@ -901,11 +916,11 @@ def generate_excel(orders, selected_fields, sum_fields, sum_results,
|
||||
cell.alignment = Alignment(horizontal='right', vertical='center')
|
||||
cell.number_format = '0.000'
|
||||
|
||||
# 如果有缺失日期,行高加大一点
|
||||
# 行高
|
||||
if missing_dates and len(missing_dates) > 0:
|
||||
ws.row_dimensions[monthly_row].height = 40
|
||||
ws.row_dimensions[monthly_row].height = 45
|
||||
else:
|
||||
ws.row_dimensions[monthly_row].height = 25
|
||||
ws.row_dimensions[monthly_row].height = 28
|
||||
except Exception as e:
|
||||
log_error(f"[日报生成] 写入月度总计时出错: {e}", 'report')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user