Commit d5c6809b by 江名洋

fix(analysis): 修复条件格式复制及模板隐藏和行高调整

1 parent a19fc9e6
...@@ -608,7 +608,9 @@ class AnalysisService: ...@@ -608,7 +608,9 @@ class AnalysisService:
formula_map, skip_external_cols = AnalysisService._extract_formulas_from_template(ws_template) formula_map, skip_external_cols = AnalysisService._extract_formulas_from_template(ws_template)
# openpyxl 的 copy_worksheet 不复制条件格式,需手动保存 # openpyxl 的 copy_worksheet 不复制条件格式,需手动保存
cf_rules = [(cf.sqref, list(cf.rules)) for cf in ws_template.conditional_formatting] # 注意: cf.sqref 是 MultiCellRange 对象,需转字符串;cf.rules 的 rule 对象需 copy 避免引用冲突
from copy import copy as shallow_copy
cf_rules = [(str(cf.sqref), [shallow_copy(r) for r in cf.rules]) for cf in ws_template.conditional_formatting]
# 复制两份"模板"sheet # 复制两份"模板"sheet
ws_ecology = wb.copy_worksheet(ws_template) ws_ecology = wb.copy_worksheet(ws_template)
...@@ -616,12 +618,14 @@ class AnalysisService: ...@@ -616,12 +618,14 @@ class AnalysisService:
ws_ecology.title = ecology_sheet_name ws_ecology.title = ecology_sheet_name
ws_nature.title = nature_sheet_name ws_nature.title = nature_sheet_name
# 保留原始"模板"sheet # 保留原始"模板"sheet(隐藏)
ws_template.sheet_state = 'hidden'
# 将条件格式复制到两个新 sheet # 将条件格式逐条复制到两个新 sheet
for sqref, rules in cf_rules: for sqref, rules in cf_rules:
ws_ecology.conditional_formatting.add(sqref, *rules) for rule in rules:
ws_nature.conditional_formatting.add(sqref, *rules) ws_ecology.conditional_formatting.add(sqref, rule)
ws_nature.conditional_formatting.add(sqref, rule)
logger.info(f"Copied {len(cf_rules)} conditional formatting rules to both sheets") logger.info(f"Copied {len(cf_rules)} conditional formatting rules to both sheets")
# 清除数据行(保留表头1-3行) # 清除数据行(保留表头1-3行)
...@@ -766,6 +770,9 @@ class AnalysisService: ...@@ -766,6 +770,9 @@ class AnalysisService:
store_name_str = str(store_name) store_name_str = str(store_name)
store_perf = db_perf.get(store_name_str, {}) store_perf = db_perf.get(store_name_str, {})
# 设置行高为1.2倍(默认15pt → 18pt)
ws.row_dimensions[row_num].height = 18
# ========== 基础门店信息 (A-J) ========== # ========== 基础门店信息 (A-J) ==========
_style_cell(row_num, 1, store_name_str) _style_cell(row_num, 1, store_name_str)
_style_cell(row_num, 2, store_row.get("兜底指标", "")) _style_cell(row_num, 2, store_row.get("兜底指标", ""))
...@@ -951,7 +958,7 @@ class AnalysisService: ...@@ -951,7 +958,7 @@ class AnalysisService:
_style_cell(row_num, 48, 0) _style_cell(row_num, 48, 0)
# ========== 兜底月份 (AW) ========== # ========== 兜底月份 (AW) ==========
_style_cell(row_num, 49, date_range) _style_cell(row_num, 49, store_row.get("兜底截止日期", ""))
# ========== 门店等级 (AX) ========== # ========== 门店等级 (AX) ==========
if total_score >= 3.0: if total_score >= 3.0:
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!