diff --git a/config.json b/config.json index 77e8564..d8eb142 100644 --- a/config.json +++ b/config.json @@ -5,17 +5,17 @@ "company_name": "gfdgdf", "email": "gfdgf", "phone": "gfdgfdg", - "store_name": "test222", + "store_name": "test1232", "country": "gfdgfd", "starting_date": "2025-09-25", "duration": 36, "store_types": [ "Convenience" ], - "currency_symbol": "$", + "currency_symbol": "€", "convenience_store_type": { "stores_number": 1233, - "monthly_transactions": 32131312, + "monthly_transactions": 3211312, "has_digital_screens": true, "screen_count": 2, "screen_percentage": 123123, diff --git a/index.html b/index.html index 6cb3393..9f4f866 100644 --- a/index.html +++ b/index.html @@ -1571,7 +1571,7 @@
-
@@ -1597,7 +1597,7 @@ diff --git a/template/Footprints AI for {store_name} - Retail Media Business Case Calculations.xlsx b/template/Footprints AI for {store_name} - Retail Media Business Case Calculations.xlsx index 95128a0..18f908b 100644 Binary files a/template/Footprints AI for {store_name} - Retail Media Business Case Calculations.xlsx and b/template/Footprints AI for {store_name} - Retail Media Business Case Calculations.xlsx differ diff --git a/update_excel_xlsxwriter.py b/update_excel_xlsxwriter.py index 0c9be8a..ab32404 100644 --- a/update_excel_xlsxwriter.py +++ b/update_excel_xlsxwriter.py @@ -3,7 +3,59 @@ import json import os import re import openpyxl -from openpyxl.utils import get_column_letter + +CURRENCY_LOCALE_MAP = { + '$': '-409', # English (US) + '€': '-2', # English (Euro) +} + +CURRENCY_BRACKET_PATTERN = re.compile(r'\[\$([^\]-]*)(-[^\]]*)?\]') + + +def apply_currency_symbol(workbook, symbol): + """Propagate the selected currency symbol across formats, labels, and charts.""" + target_symbol = (symbol or '$').strip() or '$' + + def replace_currency_token(fmt): + if not isinstance(fmt, str) or ('$' not in fmt and '€' not in fmt): + return fmt + + def _replace_match(match): + locale_hint = match.group(2) or '' + if target_symbol in CURRENCY_LOCALE_MAP: + locale_hint = f"-{CURRENCY_LOCALE_MAP[target_symbol].lstrip('-')}" if match.group(2) or locale_hint else '' + return f'[${target_symbol}{locale_hint}]' + + updated = CURRENCY_BRACKET_PATTERN.sub(_replace_match, fmt) + updated = updated.replace('"$"', f'"{target_symbol}"') + return updated + + for worksheet in workbook.worksheets: + for row in worksheet.iter_rows(): + for cell in row: + fmt = cell.number_format + updated_format = replace_currency_token(fmt) + if updated_format != fmt: + cell.number_format = updated_format + + value = cell.value + if isinstance(value, str) and not value.startswith('=') and ('€' in value or '$' in value): + new_value = value.replace('€', target_symbol).replace('$', target_symbol) + if new_value != value: + cell.value = new_value + + for chart in getattr(worksheet, '_charts', []): + axes = [getattr(chart, 'y_axis', None), getattr(chart, 'secondary_y_axis', None)] + for axis in axes: + if not axis or not getattr(axis, 'number_format', None): + continue + fmt_obj = axis.number_format + format_code = getattr(fmt_obj, 'formatCode', None) + if not isinstance(format_code, str): + continue + updated_code = replace_currency_token(format_code) + if updated_code != format_code: + fmt_obj.formatCode = updated_code def update_excel_variables(excel_path): """ @@ -153,6 +205,8 @@ def update_excel_variables(excel_path): except Exception as e: print(f"Error updating cell {cell_ref}: {e}") + apply_currency_symbol(wb, user_data.get('currency_symbol', '')) + # Force formula recalculation before saving print("Forcing formula recalculation...") wb.calculation.calcMode = 'auto'