← Blog
Two cream ceramic workbook sheets with sage and coral cells in a sage organizer.
Published on

Generate Excel reports with Python: from data to a reviewable workbook

To generate an Excel report with Python, start with a defined input, write a new workbook with a library such as XlsxWriter, and review the rows and totals before sharing it. The useful result is a file colleagues can filter and understand, with a clear reporting period and a known source.

This guide describes a recurring operations-report workflow using two sheets: Summary and Data. It uses a written example and library documentation. No workbook, database export, scheduled job, or cloud deployment was executed for this article; the review steps below are recommendations, not completed tests.

Choose Excel when readers need to work with the rows

A workbook suits a weekly report when a colleague needs to filter orders by status, sort customers, or inspect a total's underlying records. Keep a fixed-page format when the priority is a consistent reading or printing layout. The Python PDF report guide covers that separate output.

For this example, imagine a weekly orders snapshot with an order ID, business date, customer, status, and amount in one declared currency. The report owner wants an overview and the accepted rows behind it. The workbook is an exported snapshot; changes made by a recipient do not update the source system.

Agree on the reporting period and intended recipient first. “This week's orders” needs a precise start and end date, a business time zone, and a rule for late corrections. Record those choices in the report rather than relying on its filename or the recipient's memory.

Define the input before formatting the workbook

Use a complete, approved export or snapshot. Specify required columns, allowed statuses, missing-value rules, and what makes an order unique. Decide whether the report includes canceled orders and whether its total represents all accepted rows or a narrower group. Formatting cannot resolve those business definitions.

A valid empty result should say that no records matched the stated period. A failed export should stop the reporting process or produce a separate failure notice. Converting a failed query into an empty list can create a convincing report with an incorrect zero total.

The Python ETL guide describes a separate CSV validation and PostgreSQL-loading example. It does not create this workbook or provide its export. Define the field mapping and verify the export before connecting the two; the ETL guide's database integration remains untested.

Give Summary and Data different jobs

Put the report's meaning on the Summary sheet

Use the first sheet to answer what the file contains, where the data came from, and which period it covers. Include the reporting period, source or snapshot identifier, generation time with its time zone, accepted row count, currency, and relevant totals. A short note should explain exclusions or corrections that affect interpretation.

Calculate the summary from the same accepted records used for the Data sheet. For the written orders scenario, distinguish the total for all included orders from any subtotal for completed orders. Give each number a label that explains which rows it counts.

Keep the Data sheet easy to inspect

Use one header row and one record per row, with consistent columns. Freeze the headings, enable filters, and choose widths that make the main fields readable. Keep decorative titles and summary blocks outside the data range so they do not interrupt sorting and filtering.

Use restrained formatting to distinguish headers, dates, and amounts. Preserve enough detail for someone to find a specific order and reconcile the summary. Add a chart only when it answers a question the rows and totals do not answer clearly.

Use XlsxWriter for a new Excel file

XlsxWriter writes new XLSX workbooks with multiple sheets, formatting, filters, and other Excel features. It cannot read or modify an existing workbook. A workflow that must preserve an established template is a different requirement and needs a suitable editing tool.

The implementation sequence is straightforward: validate the input, calculate the report values, create the workbook, add the two worksheets, write typed cells and formatting, then close the workbook before making the completed file available. These are design steps for an implementation, not a runnable program supplied by this guide.

Write identifiers, amounts, and dates deliberately

An order ID such as 00042 is an identifier, even though it contains digits. Write it as text so its leading zeros remain meaningful. Write amounts as numeric values when recipients need numerical sorting or calculations, and declare the currency instead of relying on a symbol alone.

Define the precision and rounding policy before exporting amounts. Displaying two decimal places is a presentation rule; it does not explain how the underlying business amount was calculated. Keep the accepted source values available for reconciliation.

Excel dates use numeric values with date formatting. Follow XlsxWriter's date and time guidance when writing them. For timestamps, choose and label the report's time zone explicitly. A formatted cell should not leave readers guessing whether a time is local or UTC.

Keep source text separate from formulas

XlsxWriter's general write method can interpret strings as formulas or hyperlinks. For fields that should remain literal text, use explicit string-writing behavior or disable the automatic conversions through the documented workbook options. A customer name or imported note should not become an instruction merely because of its contents.

For the first report, prefer summary values calculated by the reporting job. XlsxWriter writes formulas but does not calculate their results; applications that do not recalculate may display cached values. The formula documentation explains this limitation. If readers need editable formulas, review their behavior in the application they will use rather than assuming every viewer calculates them identically.

Review the report before distributing it

Opening a file successfully does not establish that it describes the intended data. Use a short review checklist tied to the report's purpose:

Period and source: the labels identify the intended snapshot, dates, and currency.

Rows and totals: the accepted count and summary reconcile with the source, including the first and last expected records.

Cell meaning: identifiers retain leading zeros, amounts are usable numbers, and dates follow the stated convention.

Readability: headings, filters, frozen rows, and column widths make the data understandable without hidden assumptions.

Exceptions: an empty report, rejected input, and failed generation have distinct outcomes.

These are proposed checks. This article does not include a generated workbook or claim that Excel, LibreOffice, or another viewer has been exercised. For a real implementation, inspect the file in the recipient's application and record which output was reviewed.

Decide what happens when the report runs again

Name the output from the reporting period and a defined revision policy. A corrected internal report might replace the previous version; a review process may require each revision to be retained. Make the current version identifiable and preserve enough source information to explain why a total changed.

When a corrected export arrives, compare it with the original by ID so the reviewer can see which values changed before you replace the workbook.

Keep incomplete output separate from the file offered to readers. Treat a failed write or close as a failed report, and define how an operator recognizes and recovers from it. Overlapping jobs also need separate destinations or coordination. None of those failure-handling paths was implemented or tested here.

Restrict access to the intended recipients and define retention for both source exports and finished workbooks. Avoid publishing customer reports as public website assets. A predictable filename helps organization but does not control who can open the file.

Choose where the recurring report should run

An occasional report may be simplest on an operator's machine. A recurring job may justify a managed service or a CPU VM when it needs a stable environment, access to approved inputs, and an owner for failures. Workbook generation is a candidate CPU workload; this guide supplies no capacity, performance, or cloud-availability evidence.

Use the CPU VM buying guide to assess memory, storage, and operating responsibilities. Choose capacity from representative report sizes and simultaneous jobs rather than the number of sheets alone.

Once the reporting implementation works manually, compare cron and systemd timers for recurring execution on one Linux host. Decide how missed periods, corrections, and overlapping runs are handled. A scheduler launches the job; it does not establish that its workbook is correct or delivered to the right person.

Start with a report definition the recipient can review: the period, input, two sheet layouts, and correction policy. That gives the implementation a clear output to produce and the reader a clear result to inspect.

Your next workload belongs on Hivenet.

Pick one AI, compute, or storage workload and see the difference for yourself. Spin it up in minutes, or let our team map your fastest path to production.