Fixed issue with variables not being updated in Excel file

This commit is contained in:
denisacirstea
2025-09-12 12:37:08 +03:00
parent 2a55f69813
commit 1ae630d5d6
4 changed files with 76 additions and 35 deletions

View File

@@ -101,10 +101,16 @@ def update_excel_variables(excel_path):
# Update the cells
for cell_ref, value in cell_mappings.items():
try:
sheet[cell_ref] = value
# Force the value to be set, even if the cell is protected or has data validation
cell = sheet[cell_ref]
cell.value = value
print(f"Updated {cell_ref} with value: {value}")
except Exception as e:
print(f"Error updating cell {cell_ref}: {e}")
# Save the workbook immediately after updating the cells
print("Saving workbook after updating variables...")
wb.save(excel_path)
# Update sheet names - replace {store_name} with actual store name
store_name = user_data.get('store_name', '')
@@ -139,6 +145,23 @@ def update_excel_variables(excel_path):
os.remove(modified_file)
# Reload the workbook to get the changes
wb = openpyxl.load_workbook(excel_path)
# Re-apply the variables to make sure they weren't overwritten
print("Re-applying variables after XML modification...")
try:
sheet = wb['Variables']
for cell_ref, value in cell_mappings.items():
try:
cell = sheet[cell_ref]
cell.value = value
print(f"Re-applied {cell_ref} with value: {value}")
except Exception as e:
print(f"Error re-applying cell {cell_ref}: {e}")
# Save the workbook again
wb.save(excel_path)
except Exception as e:
print(f"Error re-applying variables: {e}")
# Save the workbook
wb.save(excel_path)