import sys
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'packages' / 'agromatrix-tools'))
from agromatrix_tools import tool_spreadsheet

spec = {
    "sheets": [
        {"name": "FieldLog", "data": [["Field", "Date", "Yield"], ["A1", "2026-02-08", 120]]},
        {"name": "Summary", "data": [["Metric", "Value"], ["Total Yield", "=SUM(FieldLog!C2:C2)"]]} 
    ]
}

out_path = "artifacts/demo.xlsx"
print(tool_spreadsheet.create_workbook(out_path, spec))
print(tool_spreadsheet.apply_table(out_path, "FieldLog", "A1:C2", "FieldLogTable"))
print(tool_spreadsheet.read_range(out_path, "FieldLog", "A1:C2"))
