Add special handling for rows 25-27 in Graphics sheet to fix formula links

This commit is contained in:
denisacirstea
2025-09-12 11:40:25 +03:00
parent df6cf5fcab
commit 885526e222

View File

@@ -165,9 +165,31 @@ def update_formulas_in_workbook(workbook, sheet_name_mapping):
sheet_updates = 0
print(f"Checking formulas in sheet: {sheet_name}")
# Special handling for Graphics sheet rows 25-27
if sheet_name == "Graphics":
# Directly access cells in rows 25-27
for row_num in range(25, 28): # 25, 26, 27
for col_idx in range(1, sheet.max_column + 1):
cell_coord = f"{get_column_letter(col_idx)}{row_num}"
cell = sheet[cell_coord]
if cell.data_type == 'f' and cell.value and isinstance(cell.value, str) and '{store_name}' in cell.value:
print(f"Special handling for Graphics cell {cell_coord}: {cell.value}")
original_formula = cell.value
updated_formula = original_formula
for old_name, new_name in sheet_name_mapping.items():
updated_formula = updated_formula.replace(old_name, new_name)
if updated_formula != original_formula:
cell.value = updated_formula
print(f"Force updated formula in {sheet_name} cell {cell_coord}")
# Iterate through all cells in the sheet
for row in sheet.iter_rows():
for cell in row:
# Skip rows 25-27 in Graphics sheet as they're handled separately
if sheet_name == "Graphics" and cell.row >= 25 and cell.row <= 27:
continue
# Check if the cell contains a formula
if cell.data_type == 'f' and cell.value:
try:
@@ -217,7 +239,7 @@ def update_formulas_in_workbook(workbook, sheet_name_mapping):
formula = new_formula
formula_updated = True
# Handle other potential reference formats
# Handle other potential reference formats
# This catches references without quotes or special formatting
pattern5 = f"({re.escape(old_name)})"
replacement5 = f"{new_name}"
@@ -229,6 +251,8 @@ def update_formulas_in_workbook(workbook, sheet_name_mapping):
formula = new_formula
formula_updated = True
# We're handling rows 25-27 separately now, so this section is no longer needed
# If the formula was changed, update the cell
if formula_updated:
try: