A Format-Aware Intake Converter for XLSX, DOCX, and PDF
A practical design for converting spreadsheets, Word documents, and PDFs into structured and readable intake digests.
TL;DR
This converter processes XLSX, DOCX, and PDF batches with format-specific readers under one shared workflow, leaving originals untouched. Spreadsheets get formula recalculation via headless LibreOffice, typed JSON, and Markdown output; Word and PDF convert to Markdown with layout limits and no OCR. Failures are logged per file while the batch continues, but a failing exit status flags results for review.
A single intake batch can contain a spreadsheet, a Word document, and a PDF. I wanted each file to produce something a person can inspect and a downstream process can read, without changing the source. The converter therefore shares one batch workflow while choosing a different reader for each format.
The spreadsheet path shows why a generic “extract text, write JSON” function is not enough. A workbook can store formulas separately from their last calculated values, and a Python reader does not calculate those formulas by itself.
Spreadsheet formulas need a separate step
In openpyxl, data_only selects the value last stored by a spreadsheet application. It does not evaluate the formula; openpyxl states this directly in its documentation [1]. Loading a workbook with data_only=True therefore cannot guarantee a newly calculated result for every formula cell.
The converter scans each workbook for formulas. If it finds any, the default path converts the workbook through LibreOffice in headless mode into a temporary directory, then reads the resulting values. The --no-recalc option skips that step. This makes recalculation explicit rather than pretending that reading a workbook and calculating it are the same operation. LibreOffice is a separate processing step, not a promise that every workbook formula will be handled correctly. Important results still need review against the spreadsheet application used as the source of truth.
Each sheet is written to typed JSON, with empty cells represented as null. Dates and times use ISO format, and trailing empty rows and columns are trimmed. The JSON also records the source name and conversion time. A Markdown output provides a sheet inventory and a short preview. The structured output is available to later processing, while the preview lets a person inspect the result without parsing every row.
Word documents and PDFs have different structure
A DOCX file stores text alongside document structure. Its main WordprocessingML document contains block-level elements, including paragraphs [2]. Tables have their own row-and-cell structure, and cells can contain paragraphs [3]. The converter reads those elements in order, maps recognized heading styles, and writes paragraphs and tables to Markdown. It processes a subset of Word features, so some layout details and document features are outside its scope.
PDF extraction has a different limitation. The converter runs pdftotext with -layout, then separates the result at page boundaries. Poppler describes -layout as maintaining the original physical layout “as best as possible” [4]. That qualification matters: the output approximates page layout but does not reproduce the page visually. Complex columns may come out in a different order, and this path does not perform OCR on image-only pages.
The outputs follow the kind of information each reader can preserve. XLSX produces both structured JSON and a Markdown preview. DOCX and PDF produce Markdown. The original files remain separate from those generated digests, so converting a batch does not require overwriting its inputs.
One batch, isolated file failures
The batch behavior is consistent even though the format readers differ. Unsupported files are skipped. If a conversion fails for one file, the tool records that failure and continues with later files. Existing outputs are skipped unless --force is supplied, so a repeat run does not need to replace digests that are already present.
An incomplete batch can still yield useful files, while its overall status must signal that review is needed. The command returns a failure status if any file failed, even when other conversions finished. That lets an operator use completed digests while still seeing that the batch needs attention. A DOCX feature outside the handled subset may lose structure; PDF layout remains best-effort; and formula recalculation may need separate validation. The converter reports these limits alongside its outputs so users can judge how much review each result needs.
I chose format-specific readers, a shared output convention, and per-file error handling. The batch workflow is consistent; the interpretation of each file still follows the structure of its source format.