Gabriel00A commited on
Commit
6e7e94c
·
verified ·
1 Parent(s): 134724c

Update process_report.py

Browse files
Files changed (1) hide show
  1. process_report.py +8 -8
process_report.py CHANGED
@@ -239,16 +239,16 @@ def _df_to_styled_excel_bytes(df: pd.DataFrame) -> bytes:
239
  - 自动列宽,但不破坏原数据
240
  """
241
  # 删除最后一行(当为空/仅包含 'nan' 或 '合计' 字样)
 
 
 
 
 
 
 
242
  if len(df) >= 1:
243
  last = df.tail(1)
244
- # 全空
245
- if last.isna().all(axis=1).iloc[0]:
246
- df = df.iloc[:-1, :]
247
- else:
248
- # 单元格值合并判断:若首列或任意列标记为 'nan'/'合计'/'总计' 等则删除
249
- row0 = last.iloc[0].astype(str).str.strip().str.lower().tolist()
250
- if any(x in ("nan", "合计", "总计", "合计:", "小计") for x in row0 if x):
251
- df = df.iloc[:-1, :]
252
 
253
  bio = BytesIO()
254
  writer = pd.ExcelWriter(bio, engine='xlsxwriter')
 
239
  - 自动列宽,但不破坏原数据
240
  """
241
  # 删除最后一行(当为空/仅包含 'nan' 或 '合计' 字样)
242
+ if len(df) > 0:
243
+ last_row = df.tail(1).astype(str).apply(lambda s: s.str.strip().str.lower())
244
+ last_joined = " ".join(last_row.iloc[0].tolist())
245
+ if any(k in last_joined for k in ["合计", "总计", "小计", "汇总"]):
246
+ df = df.iloc[:-1, :]
247
+
248
+ # (原来的代码保持不动)
249
  if len(df) >= 1:
250
  last = df.tail(1)
251
+
 
 
 
 
 
 
 
252
 
253
  bio = BytesIO()
254
  writer = pd.ExcelWriter(bio, engine='xlsxwriter')