# Track receipts in Excel: template, scripts and outputs
Checked 2026-11-07. Every script ran as shown; the lines under # $ are what it printed, cut only where you see ....
Contents
- receipt-saltmarsh.xlsx and receipt-aarenblick.xlsx are the output.xlsx files of parserkit’s recorded receipt sample runs (https://parserkit.com/samples/outputs/).
- LibreOffice ran headless to recalculate the formulas; openpyxl does not calculate formulas itself.
# BUILD_PY
from openpyxl import Workbook
from openpyxl.styles import Alignment, Font, PatternFill
from openpyxl.worksheet.datavalidation import DataValidation
ROWS = 500
LAST = ROWS + 1
COLUMNS = ["Date", "Vendor", "Category", "Paid by", "Currency", "Net", "Tax", "Total", "Month", "Receipt no.", "Checked"]
WIDTHS = [12, 28, 18, 14, 10, 12, 10, 12, 11, 13, 22]
CATEGORIES = ["Meals", "Travel", "Fuel", "Office supplies", "Software", "Equipment", "Phone and internet", "Other"]
HEAD = Font(bold=True, color="FFFFFF")
HEAD_FILL = PatternFill("solid", fgColor="1F4E46")
MONEY = "#,##0.00"
def header(ws, row, labels):
for col, label in enumerate(labels, start=1):
cell = ws.cell(row=row, column=col, value=label)
cell.font = HEAD
cell.fill = HEAD_FILL
cell.alignment = Alignment(horizontal="center")
wb = Workbook()
# Receipts: you type date, vendor, category, paid by, currency, tax and total; net and month are formulas
receipts = wb.active
receipts.title = "Receipts"
header(receipts, 1, COLUMNS)
for col, width in zip("ABCDEFGHIJK", WIDTHS):
receipts.column_dimensions[col].width = width
for row in range(2, LAST + 1):
receipts[f"A{row}"].number_format = "yyyy-mm-dd"
receipts[f"F{row}"] = f'=IF(H{row}="","",H{row}-G{row})'
receipts[f"I{row}"] = f'=IF(A{row}="","",DATE(YEAR(A{row}),MONTH(A{row}),1))'
receipts[f"I{row}"].number_format = "mmm yyyy"
for col in "FGH":
receipts[f"{col}{row}"].number_format = MONEY
receipts.freeze_panes = "A2"
receipts.auto_filter.ref = f"A1:K{LAST}"
lists = wb.create_sheet("Lists")
lists["A1"] = "Categories"
lists["A1"].font = Font(bold=True)
for row, name in enumerate(CATEGORIES, start=2):
lists[f"A{row}"] = name
lists.column_dimensions["A"].width = 22
pick_category = DataValidation(type="list", formula1=f"=Lists!$A$2:$A${len(CATEGORIES) + 1}", allow_blank=True)
pick_date = DataValidation(type="date", operator="greaterThan", formula1="DATE(2000,1,1)", allow_blank=True)
pick_date.error = "Type a date, for example 2026-11-02"
receipts.add_data_validation(pick_category)
receipts.add_data_validation(pick_date)
pick_category.add(f"C2:C{LAST}")
pick_date.add(f"A2:A{LAST}")
# Monthly: one year and one currency at a time, so amounts never mix currencies
monthly = wb.create_sheet("Monthly")
monthly["A1"], monthly["B1"] = "Year", "=YEAR(TODAY())"
monthly["A2"], monthly["B2"] = "Currency", "USD"
for cell in ("A1", "A2"):
monthly[cell].font = Font(bold=True)
header(monthly, 4, ["Month", "Receipts", "Net", "Tax", "Total"])
month_col, currency_col = f"Receipts!$I$2:$I${LAST}", f"Receipts!$E$2:$E${LAST}"
for n in range(12):
row = 5 + n
monthly[f"A{row}"] = f"=DATE($B$1,{n + 1},1)"
monthly[f"A{row}"].number_format = "mmm yyyy"
criteria = f"{month_col},$A{row},{currency_col},$B$2"
monthly[f"B{row}"] = f"=COUNTIFS({criteria})"
for col, source in (("C", "F"), ("D", "G"), ("E", "H")):
monthly[f"{col}{row}"] = f"=SUMIFS(Receipts!${source}$2:${source}${LAST},{criteria})"
monthly[f"{col}{row}"].number_format = MONEY
monthly["A17"] = "Year"
monthly["A17"].font = Font(bold=True)
for col in "BCDE":
monthly[f"{col}17"] = f"=SUM({col}5:{col}16)"
monthly[f"{col}17"].font = Font(bold=True)
if col != "B":
monthly[f"{col}17"].number_format = MONEY
header(monthly, 19, ["Category", "Receipts", "Net", "Tax", "Total"])
in_year = f'Receipts!$A$2:$A${LAST},">="&DATE($B$1,1,1),Receipts!$A$2:$A${LAST},"<"&DATE($B$1+1,1,1),{currency_col},$B$2'
for n in range(len(CATEGORIES)):
row = 20 + n
monthly[f"A{row}"] = f"=Lists!A{n + 2}"
criteria = f"Receipts!$C$2:$C${LAST},$A{row},{in_year}"
monthly[f"B{row}"] = f"=COUNTIFS({criteria})"
for col, source in (("C", "F"), ("D", "G"), ("E", "H")):
monthly[f"{col}{row}"] = f"=SUMIFS(Receipts!${source}$2:${source}${LAST},{criteria})"
monthly[f"{col}{row}"].number_format = MONEY
end = 20 + len(CATEGORIES) - 1
monthly[f"A{end + 1}"] = "No category"
for col in "BCDE":
monthly[f"{col}{end + 1}"] = f"={col}17-SUM({col}20:{col}{end})"
if col != "B":
monthly[f"{col}{end + 1}"].number_format = MONEY
monthly.column_dimensions["A"].width = 20
for col in "BCDE":
monthly.column_dimensions[col].width = 12
wb.save("receipt-tracker.xlsx")
print(f"receipt-tracker.xlsx: {ROWS} rows ready, {len(CATEGORIES)} categories, sheets {wb.sheetnames}")
# $ python build_tracker.py
# receipt-tracker.xlsx: 500 rows ready, 8 categories, sheets ['Receipts', 'Lists', 'Monthly']
# FORMULAS_PY
from openpyxl import load_workbook
book = load_workbook("receipt-tracker.xlsx")
receipts, monthly = book["Receipts"], book["Monthly"]
for cell in ["F2", "I2"]:
print(f"Receipts {cell} ({receipts[cell[0] + '1'].value}): {receipts[cell].value}")
for cell in ["B1", "B2", "A5", "B5", "C5"]:
print(f"Monthly {cell}: {monthly[cell].value}")
# $ python show_formulas.py
# Receipts F2 (Net): =IF(H2="","",H2-G2)
# Receipts I2 (Month): =IF(A2="","",DATE(YEAR(A2),MONTH(A2),1))
# Monthly B1: =YEAR(TODAY())
# Monthly B2: USD
# Monthly A5: =DATE($B$1,1,1)
# Monthly B5: =COUNTIFS(Receipts!$I$2:$I$501,$A5,Receipts!$E$2:$E$501,$B$2)
# Monthly C5: =SUMIFS(Receipts!$F$2:$F$501,Receipts!$I$2:$I$501,$A5,Receipts!$E$2:$E$501,$B$2)
# SUMMARY_PY
from openpyxl import load_workbook
book = load_workbook("receipt-saltmarsh.xlsx", read_only=True)
print(book.sheetnames)
for row in book["Summary"].iter_rows(values_only=True):
print(row)
# $ python show_summary.py
# ['Summary', 'Items', 'Taxes', 'Checks']
# ('field', 'value', 'checks', 'status')
# ('status', 'verified')
# ('values checked', '32 of 32')
# ('math_balanced', 'yes')
# ('repaired_fields', 0)
# ('merchant.name', 'SALTMARSH BAKERY', 'ocr, agreement', 'verified')
# ('merchant.address', '112 Commercial St, Portland, ME 04101', 'ocr, agreement', 'verified')
# ('merchant.phone', '(207) 555-0186', 'ocr, agreement', 'verified')
# ('receipt_number', '0417', 'ocr, agreement', 'verified')
# ('date', datetime.datetime(2026, 11, 2, 0, 0), 'ocr', 'verified')
# ('time', '8:41 AM', 'ocr, agreement', 'verified')
# ('currency', 'USD', 'ocr, agreement', 'verified')
# ('subtotal', 53.75, 'math, agreement', 'verified')
# ('tax_total', 4.3, 'math, agreement', 'verified')
# ('total', 58.05, 'math, agreement', 'verified')
# ('payment.method', 'card', None, 'unverified')
# ('payment.card_brand', 'VISA', 'ocr, agreement', 'verified')
# ('payment.card_last4', '4417', 'ocr, agreement', 'verified')
# ADD_PY
import sys
from openpyxl import load_workbook
CATEGORY_BY_VENDOR = {"SALTMARSH BAKERY": "Meals", "CONFISERIE AARENBLICK": "Meals"}
def read_summary(path):
sheet = load_workbook(path, read_only=True)["Summary"]
return {field: value for field, value, *_ in sheet.iter_rows(min_row=2, values_only=True)}
def paid_by(fields):
if fields.get("payment.card_brand"):
return f"{fields['payment.card_brand']} {fields.get('payment.card_last4') or ''}".strip()
return fields.get("payment.method") or ""
def add(tracker, outputs):
book = load_workbook(tracker)
sheet = book["Receipts"]
seen = {(sheet[f"B{r}"].value, sheet[f"J{r}"].value) for r in range(2, sheet.max_row + 1) if sheet[f"A{r}"].value}
row = next(r for r in range(2, sheet.max_row + 2) if sheet[f"A{r}"].value is None)
for path in outputs:
fields = read_summary(path)
key = (fields["merchant.name"], fields.get("receipt_number"))
if key in seen:
print(f"skipped {path}: receipt {key[1]} from {key[0]} is already in the tracker")
continue
sheet[f"A{row}"] = fields["date"]
sheet[f"B{row}"] = fields["merchant.name"]
sheet[f"C{row}"] = fields.get("category") or CATEGORY_BY_VENDOR.get(fields["merchant.name"])
sheet[f"D{row}"] = paid_by(fields)
sheet[f"E{row}"] = fields["currency"]
sheet[f"G{row}"] = fields.get("tax_total") or 0
sheet[f"H{row}"] = fields["total"]
sheet[f"J{row}"] = fields.get("receipt_number")
sheet[f"K{row}"] = f"{fields['status']}, {fields['values checked']}"
print(f"row {row}: {fields['date']:%Y-%m-%d} {fields['merchant.name']} {fields['currency']} {fields['total']:.2f}")
seen.add(key)
row += 1
book.save(tracker)
if __name__ == "__main__":
add(sys.argv[1], sys.argv[2:])
# $ cp receipt-tracker.xlsx my-receipts.xlsx
#
# $ python add_receipts.py my-receipts.xlsx receipt-aarenblick.xlsx receipt-saltmarsh.xlsx
# row 2: 2026-10-24 CONFISERIE AARENBLICK CHF 25.10
# row 3: 2026-11-02 SALTMARSH BAKERY USD 58.05
# $ python add_receipts.py my-receipts.xlsx receipt-saltmarsh.xlsx
# skipped receipt-saltmarsh.xlsx: receipt 0417 from SALTMARSH BAKERY is already in the tracker
# MONTHLY_PY
import subprocess
import sys
from openpyxl import load_workbook
currency = sys.argv[1]
book = load_workbook("my-receipts.xlsx")
book["Monthly"]["B2"] = currency
book.save("my-receipts.xlsx")
subprocess.run(["soffice", "--headless", "--calc", "--convert-to", "xlsx", "--outdir", "recalc", "my-receipts.xlsx"], check=True, capture_output=True)
monthly = load_workbook("recalc/my-receipts.xlsx", data_only=True)["Monthly"]
for month, count, net, tax, total in monthly.iter_rows(min_row=5, max_row=16, values_only=True):
if count:
print(f"{month:%b %Y} {currency}: {count} receipt, net {net:.2f}, tax {tax:.2f}, total {total:.2f}")
print("Year row:", [cell.value for cell in monthly[17]])
# $ python read_monthly.py USD
# Nov 2026 USD: 1 receipt, net 53.75, tax 4.30, total 58.05
# Year row: ['Year', 1, 53.75, 4.3, 58.05]
# $ python read_monthly.py CHF
# Oct 2026 CHF: 1 receipt, net 24.46, tax 0.64, total 25.10
# Year row: ['Year', 1, 24.46, 0.64, 25.1]
# VERSIONS_PY
import platform
import subprocess
import sys
from importlib.metadata import version
TOOLS = {
"tesseract": lambda: subprocess.run(["tesseract", "--version"], capture_output=True, text=True).stdout.split()[1],
"ollama": lambda: subprocess.run(["ollama", "--version"], capture_output=True, text=True).stdout.split()[-1],
"libreoffice": lambda: subprocess.run(["soffice", "--version"], capture_output=True, text=True).stdout.split()[1],
}
print("Python", platform.python_version())
for name in sys.argv[1:]:
print(name, TOOLS[name]() if name in TOOLS else version(name))
# $ python versions.py openpyxl libreoffice
# Python 3.12.14
# openpyxl 3.1.5
# libreoffice 25.2.3.2
End