Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
  1. Home
  2. Blog
  3. Automating the Workbook That Runs the Business
Python & Django

Automating the Workbook That Runs the Business

Automating spreadsheets with Python: reading, writing and validating Excel files that contain merged cells, several tables per sheet and numbers stored as text.

Updated 2 min readBy SpiderHunts Technologies

Free estimateNo obligation

Get a free estimate

Tell us what you need. A senior engineer reads every enquiry.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →

Quick answer — TL;DR

Spreadsheets are messier than they look — merged cells, several tables per sheet, numbers stored as text. Handle those explicitly rather than assuming a clean grid.

They are load-bearing more often than admitted

Plenty of profitable businesses run a core process in a shared workbook. Automating around it — reading from it, writing to it, validating it — is frequently more useful than replacing it.

That approach requires nobody to change how they work, which is why it is adopted where a replacement would not be.

What makes them awkward

  1. Merged cells that break row alignment
  2. Several tables on one sheet with blank rows between
  3. Headers repeated partway down
  4. Numbers stored as text, or with stray characters
  5. Dates in several formats within one column
Code that assumes a clean rectangular table with one header row will work on the sample file and fail on the real one. Every time.

Validate as you read

  • Check the expected columns exist, by name rather than position
  • Check types — a number column containing text is a signal
  • Check ranges — dates and amounts within plausible bounds
  • Check the row count against expectation
  • Report anything unexpected rather than processing it

Writing back

Writing to a workbook people also edit is where problems arise: someone has it open, formulas get overwritten, formatting is lost.

Prefer writing to a separate output file, or to a dedicated sheet nobody edits by hand. Overwriting a workbook someone is working in is a good way to lose a morning's work.

When to move on from spreadsheets

SignalMeaning
Several people editing simultaneouslyYou need a database
Versions with different totalsNo single source of truth
Formulas nobody understandsAccumulated risk
Over about 20,000 rowsPerformance and errors will rise
Everyone sees everythingA permissions problem

Two or more of those and a proper system is worth pricing. Fewer, and automating around the spreadsheet is the cheaper answer.

FAQ

Frequently asked questions

The questions readers ask us after this guide.

Still have a question?

Ask us directly — a senior engineer will get back to you.

Ask about your project

Which library should we use?

The established options handle the common formats well. What matters is the validation you build around them.

Can it work with cloud spreadsheets?

Yes, through their APIs, which is considerably better than file handling. Moving to a cloud spreadsheet is frequently the cheapest first step.

What about formulas?

Reading calculated values is usually what you want. Writing formulas programmatically is possible and frequently more trouble than it is worth.

Should we replace the spreadsheet?

Automate around it first. If the signals above apply, price a replacement as a separate decision.

Keep reading

More on Python & Django

Python & Django

An API Other Systems Can Depend On

Designing a Python API service others can depend on: validation at the boundary, consistent errors and status codes, early versioning and documentation.

Python & Django

Moving and Transforming Data Reliably

Building data pipelines in Python that cope with malformed input: restartable stages, quarantining failures, reconciling counts and alerting on absence.

Start here

A workbook that runs your business?

Automating around it is usually cheaper than replacing it. Tell us how it is used.

  1. You tell us what you needTwo minutes on the form, or a message on WhatsApp.
  2. A senior engineer reviews itAnd comes back with questions, a realistic range and an honest view on fit.
  3. Free 30-minute scoping callWe talk through scope, options and a realistic estimate — with no obligation.
Free estimateNo obligation

Talk to someone who builds this

Send a short brief and we will come back with an honest view and a realistic range.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →