DEV Community

Quiet Stack Lab
Quiet Stack Lab

Posted on

Which 1099s Are Still Missing? Build a Self-Checking Freelancer Tax Spreadsheet with Python + openpyxl

Every January the same thing happens to freelancers: 1099s trickle in, and nobody can say whether one is missing. A client forgets, a platform sends a 1099-K that includes refunds, and you only notice when your CPA asks.

I wanted a spreadsheet that answers "which 1099s am I still waiting for?" without macros, add-ons or a SaaS login, one that opens the same way in Excel and Google Sheets. Here is how I generated it with Python's openpyxl, using only native formulas, data validation and conditional formatting.

This is a record-keeping build, not tax advice. Thresholds, rates and form lines change. Check IRS.gov and talk to a CPA or enrolled agent.

1. Why generate the workbook in code?

Hand-built spreadsheets drift. When the template comes from a build.py, you get:

  • the same named ranges and row bounds everywhere, so no off-by-one SUMs
  • tests that open the generated .xlsx and check every formula points at the right range
  • one command that rebuilds the template for next year (YEAR = 2026 → 2027)

2. A dropdown for the 1099 form type

Each payment row gets a "1099 form expected" cell with a fixed list:

from openpyxl.worksheet.datavalidation import DataValidation

FORMS_1099 = ["1099-NEC", "1099-K", "1099-MISC", "No 1099"]

dv = DataValidation(type="list",
                    formula1='"' + ",".join(FORMS_1099) + '"',
                    allow_blank=True)
ws.add_data_validation(dv)
dv.add(f"F{INC_FIRST}:F{INC_LAST}")
Enter fullscreen mode Exit fullscreen mode

Inline list validation ("a,b,c") survives the trip into Google Sheets. Validation that points at a range on another sheet usually does too, but inline is the safest choice for short lists.

3. Totals by form with SUMIF / COUNTIFS

Under the log, a small table compares what you logged with what you received:

for i, form in enumerate(FORMS_1099):
    r = t + 4 + i
    ws[f"A{r}"] = form
    ws[f"B{r}"] = f'=SUMIF($F${INC_FIRST}:$F${INC_LAST},A{r},$E${INC_FIRST}:$E${INC_LAST})'
    ws[f"C{r}"] = f'=COUNTIF($F${INC_FIRST}:$F${INC_LAST},A{r})'
    ws[f"D{r}"] = f'=COUNTIFS($F${INC_FIRST}:$F${INC_LAST},A{r},$G${INC_FIRST}:$G${INC_LAST},"x")'
Enter fullscreen mode Exit fullscreen mode

If column C says 4 payments expect a 1099-NEC and column D says 3 are marked received, you know what to chase.

4. Highlight the missing ones in yellow

The useful part is a conditional format: a row turns yellow when a 1099 is expected and the "received" cell is still empty.

from openpyxl.formatting.rule import FormulaRule

ws.conditional_formatting.add(
    f"G{INC_FIRST}:G{INC_LAST}",
    FormulaRule(
        formula=[f'AND(OR($F{INC_FIRST}="1099-NEC",$F{INC_FIRST}="1099-K",'
                 f'$F{INC_FIRST}="1099-MISC"),$G{INC_FIRST}="")'],
        fill=FILL_WARN))
Enter fullscreen mode Exit fullscreen mode

Two details matter:

  1. Write the formula for the first row of the range. Excel and Sheets shift the relative row ($F5 → $F6 …) for every row. The column stays fixed with $.
  2. No IF wrapping. A conditional-format formula only needs to return TRUE or FALSE.

I used the same trick on the expense log (AND($E5<>"",$I5="") = "amount entered but no receipt ticked") and on the Schedule C summary (C{net}<0 = net loss, so check your inputs).

5. Keep yearly constants out of formulas

The tempting shortcut is to hard-code the standard mileage rate or an SE-tax percentage. Don't. They change, and a template sold or shared for a year becomes wrong in the next.

Instead, put every assumption in a labelled yellow input cell on a Start tab and reference it:

# Start tab: a deliberately blank, labelled input cell
label_val(ws, 8, "Standard mileage rate ($ per business mile)", None, inp=True,
          note="Enter the IRS rate for this tax year - check IRS.gov. Left blank on purpose.")

# Mileage tab: deduction = miles x rate (0 until the rate is filled) + parking/tolls
ws[f"G{t + 2}"] = f'=IF({START_MILE}="",0,G{t}*{START_MILE})+H{t}'
Enter fullscreen mode Exit fullscreen mode

The same goes for the quarterly estimated-tax planner. Users enter their own rate assumptions, and the sheet only tracks planned vs. paid with confirmation numbers. The due dates are shown as "verify", because they move when they fall on a weekend or holiday.

6. Test the generated file

A pytest suite reopens the output and checks the formulas, not just that the file exists:

def test_mileage_rate_is_blank_input(wb):
    assert wb["Start"][build.S_MILE].value is None
    assert "IRS.gov" in wb["Start"]["D8"].value
    assert build.START_MILE in wb["Mileage"][f"G{build.MI_TOT + 2}"].value

def test_summary_formulas(wb):
    ws = wb["Schedule C Summary"]
    for r in range(build.SC_FIRST, build.SC_LAST + 1):
        assert ws[f"C{r}"].value.startswith("=SUMIF(Expenses!")
Enter fullscreen mode Exit fullscreen mode

One more test goes further. It fills sample rows (a $10,000 1099-NEC, a $2,000 1099-K, a 50% meal, a half-business utility bill), recalculates the workbook with the formulas package and checks the totals. So the spreadsheet math is tested without opening Excel.

Grab it or build your own

If you build your own, the pattern is the same: inputs in yellow, assumptions in one place, conditional formats for "what's missing", and tests on the generated file.

Not affiliated with the IRS. Not tax, legal or accounting advice.

Top comments (0)