
On the supplier’s order sheet, two cells both display 0012. One contains a four-character identifier. The other contains the number 12 with a display format that adds zeros. If both become the same order ID in the monthly report, the total can look plausible while the underlying orders are wrong.
You can import an Excel workbook directly into DuckDB with read_xlsx. Select the worksheet by name, read its cells as text, and check the values before assigning database types. In the example below, five order rows produce two accepted orders totaling 100.00 and three rejects. Each reject keeps its original imported value and an explanation.
Create orders.xlsx in an empty working directory. Put a sheet called Notes first and a sheet called Orders second. On Orders, enter the headers order_id and amount in cells A1 and B1. This supplier uses four-digit identifiers and a single currency. Agreed amounts have at most two decimal places.
0012 and 0013 as text, with numeric amounts 40.25 and 59.75. Format the ID cells as Text before typing the values.0014 and the word pending as its amount.12 and amount 4.50. Apply the custom number format 0000 to the ID. In row 7, enter text ID 0016 and the text amount 9.999.Run the following SQL blocks in order, in one DuckDB session, with the workbook in the current directory. We tested them with DuckDB 2.0.1. The first installation needs access to DuckDB’s extension repository. The DuckDB Excel extension reads modern .xlsx files. Convert older .xls files to XLSX before using this reader.
INSTALL excel;
LOAD excel;
CREATE TEMP TABLE raw_orders AS
SELECT * FROM read_xlsx('orders.xlsx', sheet = 'Orders',
header = true, all_varchar = true, stop_at_empty = false);
Without a sheet name, the reader defaults to the first worksheet. Here that would load the supplier’s notes. header = true treats the first row of the detected data region as column names. Setting stop_at_empty = false keeps the three orders below the blank line in scope. Inspect the staging table with SELECT * FROM raw_orders; before defining rules for a different supplier.
Reading all columns as VARCHAR postpones type inference. It preserves zeros present in a text cell. It cannot reconstruct zeros supplied by Excel’s display format. Automatically padding the numeric 12 would turn it into the same identifier as the first accepted order.
CREATE TEMP TABLE checked AS
WITH cleaned AS (
SELECT order_id AS source_id, amount AS source_amount,
trim(order_id) AS id, trim(amount) AS value
FROM raw_orders
WHERE order_id IS NOT NULL OR amount IS NOT NULL
)
SELECT source_id, source_amount, id,
TRY_CAST(value AS DECIMAL(12,2)) AS amount,
CASE
WHEN NOT coalesce(regexp_full_match(id, '[0-9]{4}'), false)
THEN 'expected four-digit order ID'
WHEN NOT coalesce(regexp_full_match(value, '-?[0-9]+([.][0-9]{1,2})?'), false)
THEN 'expected amount with up to two decimal places'
WHEN TRY_CAST(value AS DECIMAL(12,2)) IS NULL
THEN 'amount exceeds DECIMAL(12,2)'
END AS reason
FROM cleaned;
The query references both required headers by name, so the supplier can swap their positions. It retains the source values next to the cleaned fields. A row with two empty cells is a spacer. A row with an ID and an empty amount is an order that needs a correction.
The amount rule accepts an optional minus sign, digits, and up to two digits after a decimal point. 9.999 fails that rule before any rounded value can reach the report. A second check catches amounts too large for DECIMAL(12,2). DuckDB’s TRY_CAST function returns NULL when conversion fails, so one bad amount can be inspected alongside the rest of the batch. If your supplier sends decimal commas or currency symbols, agree on the input convention before changing this rule.
COPY (SELECT id AS order_id, amount FROM checked WHERE reason IS NULL)
TO 'accepted.parquet' (FORMAT PARQUET);
COPY (SELECT source_id, source_amount, reason FROM checked WHERE reason IS NOT NULL)
TO 'rejected.parquet' (FORMAT PARQUET);
SELECT count(*) AS accepted, sum(amount) AS accepted_total
FROM read_parquet('accepted.parquet');
SELECT source_id, source_amount, reason
FROM read_parquet('rejected.parquet') ORDER BY source_id;
The accepted Parquet file contains text IDs 0012 and 0013, with amounts 40.25 and 59.75. The rejected file explains the other three rows. Order 0014 has a pending amount, the ID stored as 12 is too short, and order 0016 has excess decimal places. The blank line counts toward neither file. Two accepted plus three rejected accounts for every populated order row.
Read the exported files from disk when checking a run. A total calculated from the staging table alone cannot confirm what was written. For downstream analysis, see how to query Parquet files with DuckDB on CPU. If the recipient needs another workbook, the Python Excel reporting guide covers that output step.
Record the supplier workbook name, delivery date and reporting period alongside both output files. For this delivery, the two accepted orders total 100.00. Send the supplier the three rejected rows with their original values and reasons so they can correct the source workbook.
If the report must cover every order, hold it until the supplier sends a correction. Rerun the import and account for every populated row before release. If the report owner approves a partial total, label it beside the reporting period. For this workbook, write “Partial total of 100.00 for two accepted orders. Three orders await correction.”
If readers already have that partial report, keep the workbook they received and record which supplier delivery it used. Confirm the corrected workbook covers the same supplier and reporting period. If it contains only corrected rows, ask for a complete replacement before using this import. A full replacement can include orders you already counted, so recalculate the total from all accepted rows in that file. Give the report owner the filenames or IDs of both deliveries, the new accepted count and total, and any rows still awaiting correction.
The DuckDB Excel extension can read a worksheet directly, so there is no intermediate CSV conversion. That matters here because a CSV file has no worksheet names or Excel cell types. DuckDB runs the SQL locally. The temporary tables live in the current database session, and the two Parquet files keep their column types for the next job.
When a colleague needs to open the accepted orders in Excel, write a separate review copy with the same filter. This creates a new sheet from the query result. Layout and formulas from the supplier’s workbook stay in the source file.
COPY (SELECT id AS order_id, amount FROM checked WHERE reason IS NULL)
TO 'review.xlsx' (FORMAT XLSX, HEADER true, SHEET 'Accepted');
We reran the same SQL after swapping the two columns. Both exported files contained the same records. In separate tests, we renamed amount to quantity and inserted a two-cell title row above the headers. In each case DuckDB could read the sheet but could no longer resolve the required column names. It stopped before either export. For a workbook with a permanent title block, set an explicit cell range that starts on the real headers and covers the expected data, then rerun the row-count check.
For a recurring import, keep the source workbook and use a fresh output directory for each delivery. When the supplier provides a control total, compare it with the accepted total only if both cover the same orders and period. To try a scheduled run on a CPU instance with Hivenet, start with one representative workbook and record its processing time and output size before choosing an instance for the full batch.
We tested the sample workbook import locally. A live supplier delivery, a scheduled Hivenet run and the handoff to a reporting job remain untested.
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.