Abstract
Spreadsheets are characterized by their extensive two-dimensional grids, flexible layouts, and varied formatting options, which pose significant challenges for large language models (LLMs). In response, we introduce SpreadsheetLLM, pioneering an efficient encoding method designed to unleash and optimize LLMs' powerful understanding and reasoning capability on spreadsheets. Initially, we propose a vanilla serialization approach that incorporates cell addresses, values, and formats. However, this approach was limited by LLMs' token constraints, making it impractical for most applications. To tackle this challenge, we develop SheetCompressor, an innovative encoding framework that compresses spreadsheets effectively for LLMs. It comprises three modules: structural-anchor-based compression, inverse index translation, and data-format-aware aggregation. It significantly improves performance in the spreadsheet table detection task, outperforming the vanilla approach by 25.6% in GPT4's in-context learning setting. Moreover, fine-tuned LLM with SheetCompressor has an average compression ratio of 25 times, and achieves a state-of-the-art 78.9% F1 score, surpassing the best existing models by 12.3%. Finally, we propose Chain of Spreadsheet for downstream tasks of spreadsheet understanding and validate it in a new and demanding spreadsheet QA task. We methodically leverage the inherent layout and structure of spreadsheets, demonstrating that SpreadsheetLLM is highly effective across a variety of spreadsheet tasks.
Introduction
Spreadsheets serve as a fundamental tool for data management and analysis across industries. However, their two-dimensional structure, hierarchical headers, and flexible layouts present unique challenges for Large Language Models (LLMs), which are primarily designed for sequential text. Standard "vanilla serialization"—converting grids into linear Markdown or HTML strings—often fails due to extreme token consumption and the loss of critical spatial relationships.
SpreadsheetLLM addresses these hurdles through a novel encoding pipeline that preserves semantic structure while drastically reducing the token footprint. By leveraging the inherent homogeneity and structural patterns of spreadsheets, the framework enables LLMs to perform complex reasoning and understanding tasks efficiently.
Methodology: The SheetCompressor Framework
The core innovation of SpreadsheetLLM is SheetCompressor, a three-stage encoding framework designed to create a compact "skeleton" of a spreadsheet:
- Structural-Anchor-Based Extraction: Large spreadsheets often contain repetitive data blocks. This module identifies "structural anchors"—heterogeneous rows and columns at table boundaries—and prunes redundant intermediate data, maintaining the table's overall scope without excessive tokens.
- Inverted-Index Translation: To avoid repeating addresses for every cell, this module creates a lossless dictionary. It indexes non-empty cell contents and merges addresses with identical values (e.g.,
{"Total": "A10, F10"}), which is particularly effective for sparse or repetitive sheets. - Data-Format-Aware Aggregation: For layout understanding, the type of data (e.g., Currency, Date) is often more informative than the specific value. This module clusters adjacent cells with identical formats, representing entire regions with a single format string to further compress the input.
Additionally, the authors introduce Chain of Spreadsheet (CoS), a two-stage reasoning process. In CoS, the model first identifies relevant table boundaries within the compressed sheet and then performs targeted analysis or question answering on that specific segment.
Evaluation and Results
The framework was evaluated using the TableSense benchmark for table detection and a newly introduced Spreadsheet QA dataset consisting of 307 manually crafted Q&A pairs across 64 complex spreadsheets.
Key results include:
- Efficiency: SheetCompressor achieved an average compression ratio of 25x, reducing API costs by approximately 96%.
- Accuracy: On table detection tasks, SpreadsheetLLM achieved a state-of-the-art 78.9% F1 score, a 12.3% improvement over previous CNN-based models.
- LLM Enhancement: Integrating SheetCompressor improved GPT-4’s performance on table detection by 25.6% in in-context learning scenarios.
Discussion and Future Work
While SpreadsheetLLM significantly advances spreadsheet understanding, certain limitations remain. Data-format-aware aggregation, while efficient for layout, can discard specific numerical details needed for precise arithmetic queries. Furthermore, current models do not yet fully utilize visual features like cell background colors or complex borders. Future research will explore semantic compression—grouping data by natural language categories—and better integration of visual cues to further enhance model performance.
Summary updated