Large XLSX Files: Memory, Performance and Safe Processing Strategies

November 08, 2026 · XLSX.now Editorial · XLSX Troubleshooting

Cover used-range bloat, styles, shared strings, streaming reads/writes and split/export choices.

Diagnose Used-Range Bloat Without Opening the File

A file may report 50,000 populated rows while the underlying XML declares a dimension of A1:Z1048576. This mismatch—used-range bloat—forces any application to allocate memory for millions of empty cells. Detection does not require opening the file in Excel.

Extract the workbook (an XLSX file is a ZIP archive) and inspect xl/worksheets/sheet1.xml. Locate the <dimension> element:

<dimension ref="A1:Z1048576"/>

If the row or column bound exceeds your known data extent, the file is bloated. To correct it:

  1. Open the file in an editor that supports true range reset: LibreOffice Calc or Google Sheets. (Excel's "UsedRange" reset via VBA is unreliable for severe cases.)
  2. Select the first entirely empty row below your data, then delete all rows to the bottom of the sheet. Repeat for columns to the right of your data.
  3. Save as a new XLSX file. Compare file sizes—a reduction from 200 MB to 10 MB is common.

If the file cannot be opened in any GUI, edit the XML directly. Back up the original, then modify the ref attribute to match the actual data extent. An incorrect bound truncates data silently. Verify the new extent by counting row elements in the sheet XML before repacking:

grep -c '<row ' xl/worksheets/sheet1.xml

Identify and Reduce Style Proliferation

Every unique combination of font, border, fill, alignment, and number format occupies a <xf> entry in xl/styles.xml. Pasting from multiple sources or applying conditional formatting cell-by-cell can generate tens of thousands of entries. Each is small, but 50,000 style definitions inflate file size and degrade parser performance.

Measure the style count:

grep -o '<xf ' xl/styles.xml | wc -l

A workbook with fewer than 500 entries is typical. Above 2,000, load times increase measurably. Above 10,000, many libraries fail to parse the file. The MS-XLSX specification (section 2.6.2) defines how cells reference styles via zero-based indices; a reference to a deleted entry produces a malformed file.

Remediation requires style normalization:

  • LibreOffice Calc: Format > Clear Direct Formatting, then reapply only necessary styles.
  • Excel: No built-in deduplicator exists. Third-party tools or VBA scripts that iterate the UsedRange and consolidate identical formats are required.
  • After normalization, save the file. The result is often 10–20% of the original size.

Understand Shared String Table Limits

XLSX stores text in a shared string table (xl/sharedStrings.xml). Each unique string appears once; cells reference it by integer index. This design introduces two constraints:

  • String length: The practical limit for a single shared string is 32,767 characters. Excel truncates longer strings on save. The underlying XML schema permits larger values, but the application behavior governs.
  • Memory pressure: A streaming reader must load the entire shared string table into memory to resolve cell references. For a file with 5 million unique strings, this can require 8–12 GB of RAM, independent of row-by-row processing.

Streaming writers that flush the string table incrementally avoid this accumulation. If your output contains millions of unique strings, export to CSV or Parquet instead—neither format imposes a shared string structure.

Use Streaming for Reads and Writes

Loading an entire workbook into a DOM parser guarantees memory exhaustion for large files. Streaming (SAX-style) parsers process rows sequentially and keep only the current window in memory.

For reading:

  • Python: openpyxl loads the full workbook and is unsuitable for large files. Use pandas with engine='calamine' (Rust-based, reads sheet data only, no formatting). For direct XML access, use xml.etree.ElementTree with iterparse on the sheet XML extracted from the ZIP.
  • Node.js: The exceljs library supports streaming reads with an event-based row iterator.
  • Command line: ssconvert (Gnumeric) with --export-type=Gnumeric_gnumeric:xml:stream processes large workbooks without full loading.

For writing:

  • Write to CSV first, then convert to XLSX using xlsxwriter (Python), which writes row-by-row and never holds the full workbook in memory.
  • If writing directly to XLSX, flush the row buffer every 10,000 rows and reset it. This prevents unbounded memory growth.

The MS-XLSX specification (section 2.1) describes the ZIP container structure. Each sheet is a separate XML entry, so a streaming parser can target a single sheet without decompressing the entire archive into memory.

Split, Export, or Accept the Hard Limits

Some files exceed what the XLSX format or its implementations support. The hard limits are:

  • Rows per sheet: 1,048,576. Exceeding this causes truncation or refusal to open.
  • Columns per sheet: 16,384 (column XFD). Additional columns are silently dropped.
  • ZIP entry size: 4 GB uncompressed per entry. A single sheet XML exceeding this size is unreadable.
  • Numeric precision: 15 significant digits. Values beyond this are rounded on save and load.

When a file hits these limits, options are:

  • Split by row range: Write sheets in batches of 500,000 rows within a single workbook, or split across multiple workbooks.
  • Split by logical partition: If data segments by year, region, or category, create separate files per segment.
  • Export to a format without these limits: CSV has no row limit. Parquet is columnar, compressed, and fast to query. SQLite provides a relational database with SQL access. Each conversion discards formatting, formulas, charts, and data validation.
  • Link to a database: Connect Excel to an external database via ODBC and query only the required subset.

What Conversion Cannot Recover for Large XLSX Files

Formulas are not evaluated during export to CSV or Parquet. If the XLSX was last saved with calculated values, those values appear in the output; otherwise, the cell contains an error string. The formula text itself is lost. Pivot caches, VBA macros, embedded charts, images, and data validation rules are absent from all non-XLSX outputs. The only lossless round-trip is XLSX to XLSX. Every other format discards at least one data dimension.

Before batch processing, diagnose used-range bloat and style proliferation. A file with both will fail in any tool that attempts a full load. Resolve those structural issues first, then determine whether streaming, splitting, or format conversion is the correct next step.