Automating & delivering reports
Excel in web apps
Download endpoints and uploads in Flask, FastAPI and Django, built in memory.
Start with the full guides
The long-form treatment of excel in web apps, with the reasoning the shorter pages assume.
Step-by-step how-tos
One task each, with code you can copy, run and adapt.
- How-toAdd an Export to Excel Action in Django AdminGive every Django admin changelist a proper Excel export: a reusable ModelAdmin mixin that turns list_display into columns with their admin labels, readable choice and boolean values, local dates, an action for selected rows and a button that exports everything matching the current filters, a dedicated export permission, a row limit, and tests with the Django test client.
- How-toBuild a Gradio App That Cleans an Uploaded Excel FileGive colleagues a browser tool for cleaning their own Excel files with Gradio: upload a workbook, pick the sheet from a list filled in on upload, choose cleaning options, see a preview and a summary of what changed, and download the cleaned file, with friendly error messages, upload limits, temporary-file clean-up and tests through the Gradio client.
- How-toBuild a Streamlit App to Upload and Download Excel FilesTurn an Excel-processing script into a small web app with Streamlit — upload a workbook, pick a sheet and columns, see the result and download it as a new .xlsx. Covers reading uploads in memory, caching so every click does not re-read the file, building the download only when it is clicked, friendly errors, upload limits and tests with AppTest.
- How-toBuild an Excel Workbook in Memory with BytesIOCreate .xlsx entirely in memory with pandas, xlsxwriter or openpyxl: the close-and-seek rules, in_memory mode, sending bytes to S3 or email, and reading them back.
- How-toCache Generated Excel Files in a Web AppStop a web app rebuilding the same Excel export on every click: key a file cache on the request parameters plus a data version, write cached workbooks atomically, answer repeat downloads with an ETag and 304 Not Modified, keep two users from building the same file at once, and evict old files by age and total size — tested end to end with Flask's test client.
- How-toDownload an Excel File from a Dash AppAdd an "Export to Excel" button to a Plotly Dash dashboard: dcc.Download with a callback that sends exactly the data the user filtered, a formatted multi-sheet workbook built in memory, a sensible file name, unit tests that call the callback and open the workbook it returns, and a Flask route on the Dash server for exports too large to send through a callback.
- How-toExport a Django Queryset to ExcelTurn a Django queryset into a formatted .xlsx download: values() and related fields, iterator() for large exports, permissions, admin actions and a view test.
- How-toGenerate Large Excel Exports in a Background JobStop big "Export to Excel" requests from timing out: accept the request and return a job ID at once, build the workbook in a background worker that streams rows from the database into xlsxwriter's constant-memory mode, report progress through a status endpoint, serve the finished file by link, and expire old files.
- How-toHandle an Uploaded Excel File in Flask and FastAPIReceive a spreadsheet upload safely: body-size limits, magic-byte checks, BytesIO parsing, column validation with real sheet row numbers, and background processing for large files.
- How-toImport an Excel File into Django ModelsLoad a spreadsheet of products, customers or prices into a Django database the safe way: read every cell as text, validate each row with the model's own full_clean, report errors by Excel row number, reject duplicate keys in the file, create missing related objects, upsert everything in one transaction with bulk_create, and return an error workbook the uploader can fix.
- How-toReturn an Excel File from a Flask Download EndpointA complete Flask export route: build the workbook in memory, set the download headers, format the sheet, handle empty results and errors, and test the response.
- How-toReturn an Excel File from AWS Lambda Through API GatewayServe a generated Excel workbook as a download from an AWS Lambda function behind API Gateway: build the file in memory, return it base64-encoded with isBase64Encoded, the right headers and filename, the extra binary media type setting a REST API needs, validation of query parameters, the 6 MB response limit and a pre-signed S3 redirect for bigger files, tested locally with event dictionaries and moto.
- How-toStream an Excel File from a FastAPI EndpointServe .xlsx from FastAPI without blocking the event loop: StreamingResponse, sync versus async routes, threadpool offload, background jobs and typed error handling.
- How-toValidate an Uploaded Excel File Before Processing It in a Web AppCheck an uploaded workbook in layers, cheapest first — the bytes, the zip container, then the rows — so renamed CSVs, old .xls files, password-protected workbooks, macros, external links and compression bombs are refused in under a millisecond, and data errors come back as a list of exact cells the user can fix.
- How-toSchedule Excel Reports with Celery BeatRun recurring Excel reports inside an application that already uses Celery: a report task with automatic retries and time limits, a beat schedule with crontab entries in the right time zone, the rule that exactly one beat process may run, testing the task with a real in-process worker, and database-backed schedules people can edit.
- How-toTrigger an Excel Report from a WebhookBuild an Excel report the moment something happens instead of on a timer: a small FastAPI endpoint that receives a webhook, verifies its HMAC signature and timestamp, ignores duplicate deliveries, answers within milliseconds with 202 Accepted, and builds the workbook in the background — tested end to end with FastAPI's test client.
Follow it through a track
Prefer an ordered route? These tracks cover excel in web apps along the way, in the order that builds on itself.
Related topics
Subjects that keep turning up on the same pages as this one, most overlap first.
Excel in web apps is part of Automating & delivering reports.