AgentCrafts

Python scripts for spreadsheet automation: when they beat a workflow tool

A spreadsheet with rules in it is hard to test and hard to change. When a small Python script is the better answer and what it costs to maintain.


Most teams do not start with a spreadsheet. They start with a small list, a formula nobody fully understands, and one person who knows which cell to fix when the numbers are wrong. Then the list grows, a second person needs it, and the formulas start to change on a Friday afternoon.

At that point the spreadsheet stops being a database and starts being a piece of software that happens to live in a grid. The question I am asked most often at that stage is whether to move it into a workflow tool or write some code. My answer is usually: not yet. Here is the line I actually use.

When a spreadsheet is still fine

A spreadsheet is a good place for a process that is still moving. If the rules change weekly, if the person who owns it is the only person who reads it, and if a mistake is caught within a day, a spreadsheet with a few formulas is usually the fastest answer.

The problems start when one of these becomes true:

  • The same calculation is repeated in five tabs with slightly different wording
  • A formula is copied down a column and breaks silently at row 400
  • Nobody can say what a column means without asking the person who built it
  • The same paste happens every Monday and takes most of an hour
  • Two people edit the file and one of them loses a change

None of those are solved by a better formula. They are solved by moving the rules out of the grid and into code, or into a workflow.

The line between a workflow tool and a script

A workflow tool such as Make or Zapier is good at moving data between systems. It triggers on an event, calls an app and passes a payload along. Its strength is the connector library and the visual view of the flow.

A Python script is good at deciding things. It can read a file, apply a rule with fifty branches, look up a reference list and write the result back. Its strength is logic that a visual builder would turn into a mess of filters and routers.

The test I use is simple. Is the work about moving data between apps, or about working out what the data means? Moving data, use a workflow tool. Working out what the data means, write a script.

What a script does better

Deterministic logic

The same input gives the same output. If a row is missing a postcode, the script raises an error or writes a blank. It does not decide the row looks unusual. For reconciliation, billing and anything where a number has to be right, that predictability is worth more than flexibility.

Version control

A script lives in a repository. Every change has a message, a diff and a history. You can see what changed last Tuesday and why the rule for international orders moved. Spreadsheets have version history in the product, but it is a flat list of copies with no explanation attached.

Tests

This is the part that changes the economics. Once the rules sit in a script, you can write a test for the awkward rows: the order with two addresses, the refund for less than the original, the customer whose name is spelled two ways. Run the test on every change and you know you have not broken the case that cost you a customer last year.

Repeatable runs

The script can run on one file today and on last quarter's file tomorrow, with the same rules and the same output. Producing last week's numbers with this week's method is a normal request, and with code it is a small change.

What a workflow tool does better

I do not want to push scripts at people who do not want to maintain code. A hosted workflow wins when the steps are a simple sequence, the apps have good connectors and the mapping is straightforward, or when somebody who is not a programmer needs to open it and see what it does.

The honest trade is maintenance. A hosted workflow is maintained by the platform plus whoever understands the scenario. A script is maintained by whoever understands the code. If neither of those people exists in your business, a workflow tool is the safer buy even when the logic is slightly worse.

The one file that grows into a mess

Every script project has a moment where somebody opens one file and winces. It started as forty lines and it is now nine hundred, with functions named process_data_2 and a block of copied logic nobody dares touch.

I have inherited these. My rule is that a script over about three hundred lines is no longer a script, it is an application wearing a script's clothes. The fix is not a rewrite, it is splitting: one module for reading, one for cleaning, one for the rules, one for writing the output. The entry point should read like the process it automates, in order, with no logic inside it.

Keeping it readable

A few habits I insist on, because they are the difference between a script that lasts three years and one that gets abandoned:

  • One file per job, named after the job rather than the step
  • Type hints on function arguments, so the wrong shape of data fails loudly
  • A config file for anything that changes between environments
  • A log line at the start and end of every run, with row counts
  • A README that says what the script does, what it expects and what it does not handle
  • A test file that runs against messy sample data, not a tidy one

None of that is clever. It is simply what stops the thing from rotting.

How I decide

I ask three questions. How often does it run? What happens when it is wrong? Who is going to change it when the rules change?

If it runs weekly, the rules are stable and somebody is comfortable with code, a script is usually right. If it runs on every event, the steps are simple and the team needs to see the flow, a workflow tool is usually right. If nobody will own it either way, the honest answer is to leave the spreadsheet in place and remove the manual paste.

If you want a second opinion on where the line sits for your setup, the automation and integrations service explains how I scope that work, and you can ask for a free project review with a description of the spreadsheet you are trying to automate.

If you want the commercial side of it, the automation and integrations service covers how I connect the tools.

The automation and integrations service covers how I build this, and the pricing page explains what decides the cost.

If you want the commercial side of it, the automation and integrations service covers how I build this kind of thing, and the pricing page explains what moves the cost of a project.


Workflow automation

All blogs

Common questions

Questions about automating spreadsheets with Python

should I use python or a spreadsheet for automation

Use a spreadsheet while the rules are still changing and one person owns it. Move to Python when the rules are stable, the same calculation appears in several places, or you need tests and a history of every change.

is python better than zapier for spreadsheet tasks

Not on its own. Zapier or Make are better at moving data between apps. Python is better at deciding things: complicated rules, deduplication, reconciliation and anything where the same input must give the same output every time.

how do I stop a python script becoming a mess

Keep one file per job, split anything over roughly three hundred lines into reading, cleaning, rules and writing, add type hints, log row counts at the start and end of each run, and keep a test file that runs against messy sample data.

what python libraries work best with google sheets

The official Google Sheets API client, or gspread for simpler work, alongside pandas for reading and writing tables. For Excel files, openpyxl and pandas cover most cases. For larger volumes, pull the data into a database rather than holding a spreadsheet open.

how long does it take to automate a spreadsheet

It depends on how tangled the rules are. A clean weekly extract with a handful of rules is a small job. A workbook with years of merged cells and inconsistent headers is a data cleanup first and an automation second.

can a python script replace google sheets formulas

It usually does not need to. The script reads the file, applies the rules once in one place and writes a clean output. The formulas stay for the people who still look at the sheet by hand, and the code becomes the single source of truth.

do I need to know how to code to maintain a python script

Someone does, but it does not have to be you. If nobody on the team will ever read the code, a hosted workflow tool is the safer choice because it can be edited in a browser and the platform looks after the runtime.

Where this fits

The connections that make an agent useful: your CRM, inbox, helpdesk, spreadsheets and internal software.

Automation and integrations

Keep reading

Let's build

Let's discuss your workflow

Tell me what your team does by hand every week. I'll tell you honestly whether an agent or automation is the right answer, what it would take, and what it needs to keep running.