Search by

avadim / fast-excel-reader

avadim

Lightweight and very fast XLSX Excel Spreadsheet and CSV Reader in PHP

Package info

github.com/aVadim483/fast-excel-reader

pkg:composer/avadim/fast-excel-reader

Statistics

Installs: 924 177

Dependents: 8

Suggesters: 0

Stars: 107

Open Issues: 0


README

GitHub Release Packagist Downloads GitHub License Static Badge

FastExcelReader

πŸ‡¬πŸ‡§ English Β· πŸ‡·πŸ‡Ί Русский

FastExcelReader is a part of the FastExcelPhp Project which consists of

Introduction

This library is designed to be lightweight, super-fast and requires minimal memory usage.

FastExcelReader can read Excel compatible spreadsheets in XLSX format (Office 2007+), legacy XLS format (Office 97-2003) and CSV-files. It only reads data, but it does it very quickly and with minimal memory usage.

Features

XLSX format support

  • Supports XLSX format (Office 2007+) with multiple worksheets
  • Supports autodetect currency/numeric/date types
  • Supports auto formatter and custom formatter of datetime values
  • The library can define and extract images from XLSX files
  • The library can read styling options of cells - formatting patterns, colors, borders, fonts, etc.

XLS format support

  • Supports legacy XLS format (Office 97-2003, BIFF8) with the same API as XLSX
  • Values, dates, cell styles, formula text and images are all returned in the same shape
  • The format is chosen by the file signature, not by the extension
  • Streaming row iteration; workbook metadata, shared strings and images still consume memory

CSV format support

  • Openable via Excel::open() as a normal one-sheet workbook with the same reading API as XLSX/XLS, or via Excel::openCsv() for the low-level engine
  • Delimiter Detection: Automatic detection or manual specification of column delimiters.
  • Wide Encoding Support: Any encoding supported by your PHP environment
  • Supports fields with or without quotes, and escaped quotes (doubled quotes).
  • Multi-line Fields Handles line breaks within quoted fields.
  • Two modes - strict (follows RFC 4180) and tolerant (with non-standard CSV files)

Installation

Use composer to install FastExcelReader into your project:

composer require avadim/fast-excel-reader

Quick start

use \avadim\FastExcelReader\Excel;

// XLSX, legacy XLS and CSV are all opened this way; the reader is chosen by the file signature
$excel = Excel::open(__DIR__ . '/files/demo.xlsx');

// Read all rows into a two-dimensional array (ROW x COL)
$rows = $excel->readRows();

// Or read row by row (memory efficient)
$sheet = $excel->sheet();
foreach ($sheet->nextRow() as $rowNum => $rowData) {
    // handle $rowData
}

See more in the Getting Started guide.

Choosing an opening method

Since 4.5, use an explicit factory when the format or API level is known:

Method Returns Use
Excel::open($file, $options) AbstractBook Detect XLSX/XLS/CSV by content
Excel::openXlsx($file) Excel Require XLSX, without falling back to CSV
Excel::openXls($file) XlsBook Require legacy BIFF8 XLS
Excel::openCsvBook($file, $options) CsvBook CSV through the common book/sheet API
Excel::openCsvReader($file, $options) CsvReader Low-level CSV engine

CSV options accept an array, CsvOptions, or null. Explicit CSV factories accept an empty CSV; the generic open() rejects empty input. open() only supports forcing ['format' => 'csv']; use openXlsx() or openXls() to require those formats.

Preparing for 5.0: openCsv() still returns CsvReader in 4.x, but is planned to return CsvBook in 5.0. Replace low-level calls with openCsvReader() to retain methods such as getCsvLine() and fromRow(). Choose openCsvBook() for book/sheet code; getReader() on that book also provides the low-level engine.

isXlsx() checks a ZIP signature and isXls() an OLE2 signature; neither proves that an arbitrary container is a supported workbook. validate() checks required XLSX parts and XML well-formedness, not full OOXML schemas or formula correctness.

Format capabilities and resource limits

Capability XLSX XLS (BIFF8) CSV
Common book/sheet API and row generators Yes Yes Yes, one sheet
Styles and embedded images Yes Yes, format limitations apply No
Formula text / cached results Read, not calculated Read, supported formula subset Plain text
Cell hyperlinks / document properties Yes Not exposed by these APIs No
Input encoding XML encoding BIFF strings/codepage Auto or explicit CsvOptions

readRows() collects the result in memory; use nextRow() for large imports. Shared strings are loaded into memory for XLSX and XLS, and XLS also loads its global image store. Streaming rows therefore does not imply constant memory for the whole workbook. openString() and openStream() copy input to disk. Their successful temporary files live until process shutdown, including in long-running workers; destroying a book does not remove them immediately. A book-level close() is not available in 4.5.

Documentation

Guides

API Reference

Examples

You can find more examples in the /demo folder.

Changelog

See CHANGELOG.md for the list of changes.

Do you want to support FastExcelReader?

if you find this package useful you can give me a star on GitHub.

Or you can donate me :)

  • USDT (TRC20) TSsUFvJehQBJCKeYgNNR1cpswY6JZnbZK7
  • USDT (ERC20) 0x5244519D65035aF868a010C2f68a086F473FC82b
  • ETH 0x5244519D65035aF868a010C2f68a086F473FC82b