"""Apply the agent's first, faulty request with openpyxl and save.

The same three writes as bad-request.json, by cell coordinate:
  Regions!C5  Europe Q3 = 6,240
  Regions!B6  APAC 4,410, written to the Q2 column instead of Q3
  Summary!B7  variance formula naming a table column that does not exist

    python openpyxl_edit.py q3-close.xlsx q3-close-openpyxl.xlsx
"""

import sys
import warnings

from openpyxl import load_workbook

source, target = sys.argv[1:3]
with warnings.catch_warnings(record=True) as caught:
    warnings.simplefilter("always")
    wb = load_workbook(source)
    wb["Regions"]["C5"] = 6240
    wb["Regions"]["B6"] = 4410
    wb["Summary"]["B7"] = "=SUM(Regions[Q3 Actual])-Regions!C10"
    wb.save(target)
for warning in caught:
    print(f"warning: {warning.message}", file=sys.stderr)
print(f"saved {target}")
