Gabriel00A commited on
Commit
7c45b63
·
verified ·
1 Parent(s): 39fa14e

Update process_report.py

Browse files
Files changed (1) hide show
  1. process_report.py +7 -5
process_report.py CHANGED
@@ -7,7 +7,7 @@ process_report.py
7
  1) 增强导出的 Excel 样式,解决:部分边框不全、Q 列以后列无边框、去掉最后一行(若为汇总/空行)的问题;
8
  2) 在 Resend 发送失败并怀疑为 Gmail "550-5.7.1 unsolicited mail" 时,自动尝试用更“简洁/友好”的邮件内容重试一次;
9
  3) 可选 SMTP 回退:当 Resend 失败且你提供 SMTP_* 环境变量时,会尝试通过 SMTP 重发(仅作回退);
10
- 其他数据处理逻辑(表头识别、分组、聚合、进度判定)保持原样,未做不必要修改
11
  """
12
 
13
  import os
@@ -233,7 +233,7 @@ def _df_to_styled_excel_bytes(df: pd.DataFrame) -> bytes:
233
  """
234
  增强导出:
235
  - 如果最后一行是全空或包含合计/总计/nan文字,删除它(用户不需要最后一行)
236
- - 设置统一边框,覆盖到 Q 列之后(至少到 Z
237
  - 标红逾期行
238
  - 自动列宽,但不破坏原数据
239
  """
@@ -274,10 +274,12 @@ def _df_to_styled_excel_bytes(df: pd.DataFrame) -> bytes:
274
  for col_num, value in enumerate(df.columns.values):
275
  worksheet.write(0, col_num, value, header_format)
276
 
277
- # 统一边框:设置到至少 Z 列(列索引 25,或当前实际列数
278
  nrows = len(df)
279
- ncols = max(df.shape[1] - 1, 25) # 0-based index; 证至少到 Z
280
- # conditional_format with 'no_errors' ensures each cell gets the format
 
 
281
  worksheet.conditional_format(1, 0, nrows, ncols, {'type': 'no_errors', 'format': border_fmt})
282
 
283
  # 标红逾期行(与原逻辑保持一致)
 
7
  1) 增强导出的 Excel 样式,解决:部分边框不全、Q 列以后列无边框、去掉最后一行(若为汇总/空行)的问题;
8
  2) 在 Resend 发送失败并怀疑为 Gmail "550-5.7.1 unsolicited mail" 时,自动尝试用更“简洁/友好”的邮件内容重试一次;
9
  3) 可选 SMTP 回退:当 Resend 失败且你提供 SMTP_* 环境变量时,会尝试通过 SMTP 重发(仅作回退);
10
+ 其他数据处理逻辑(表头识别、分组、聚合、进度判定)保持原样,未做不必要修改.
11
  """
12
 
13
  import os
 
233
  """
234
  增强导出:
235
  - 如果最后一行是全空或包含合计/总计/nan文字,删除它(用户不需要最后一行)
236
+ - 设置统一边框,覆盖到实际数据的最后一列(不延伸到 Q 列之后)
237
  - 标红逾期行
238
  - 自动列宽,但不破坏原数据
239
  """
 
274
  for col_num, value in enumerate(df.columns.values):
275
  worksheet.write(0, col_num, value, header_format)
276
 
277
+ # 仅在实际数据范围内画边框(最后一= df.shape[1]-1
278
  nrows = len(df)
279
+ # 如果 df 为空,确ncols 不为负
280
+ ncols = max(df.shape[1] - 1, 0)
281
+ # conditional_format with 'no_errors' ensures each cell gets the format; header is row 0, data rows 1..nrows
282
+ # last row index for conditional_format should be nrows (since header 0, data rows occupy 1..nrows)
283
  worksheet.conditional_format(1, 0, nrows, ncols, {'type': 'no_errors', 'format': border_fmt})
284
 
285
  # 标红逾期行(与原逻辑保持一致)